所以我一直在寻找一个半小时,但我无法弄清楚.我不想设置自定义主题.我想设置一个内置到Android的AlertDialog主题.
根据d.android.com我可以这样做:
public AlertDialog.Builder (Context context)
Run Code Online (Sandbox Code Playgroud)
或这个
public AlertDialog.Builder (Context context, int theme)
Run Code Online (Sandbox Code Playgroud)
所以我这样做,它完美地工作:
AlertDialog action_btn = new AlertDialog.Builder(MyActivity.this).create();
Run Code Online (Sandbox Code Playgroud)
但是,当我需要添加一个主题时,我从eclipse中得到一个错误:
AlertDialog action_btn = new AlertDialog.Builder(MyActivity.this, AlertDialog.THEME_TRADITIONAL).create();
Run Code Online (Sandbox Code Playgroud)
如果有人可以帮我解决如何设置主题的话,我仍然是编程的新手.
我还有一个奖金问题:
我不能只是AlertDialog()为了工作,让它工作我需要输入AlertDialog.Builder(),但在开发人员网站上,他们似乎都有相同的方法和构造函数.有什么区别/为什么不起作用AlertDialog()?
这是我第一次使用外部库,我对删除所有错误感到有些紧张.添加库时,我会使用相同的修复程序"删除@Override注释"给出一大堆错误.
解决此问题的方法是将JDK增加到1.6:ActionBarSherlock库在导入后会出现错误
但现在我担心我的其他应用程序......我是否以错误的方式编译它们?另外,我有1.7的JDK可用,我应该使用它而不是1.6吗?对不起,我真的不知道区别.
我正试图SYSTEM_UI_FLAG_LOW_PROFILE在视图上使用此标志.我的问题比这更深刻.我真正的问题是我在浏览文档时很难找到如何实际实现它.我发现自己陷入了这种困境.任何人都可以告诉我如何设置标志,但通过使用文档而不是找人发布一些示例代码让我"偷"?让我说我所拥有的只是eclipse和所有下载的android文档,我不知道如何设置它,我怎么能学习?这更像是一个"学习编程"类型的问题,但仍然是一个真正的问题,我希望有人可以帮助我.
我可以通过阅读文档得到最好的结论:
setContentView(R.layout.start);
setSystemUiVisibility(SYSTEM_UI_FLAG_LOW_PROFILE):
Run Code Online (Sandbox Code Playgroud) 假设我在 sqlite 数据库中创建了 5 个条目。
_id | Name
1 Tom
2 Oskar
3 Matt
4 Mike
5 Ed
Run Code Online (Sandbox Code Playgroud)
如果我删除数字4和5,我就只有1-3了。然后我执行 max _id 查询,然后得到数字 3。但是,我当然想要下一个自动递增的 _id。在这个例子中,如何得到数字“6”?
我在我的一个程序中运行这段代码.
public String[] gen_phase_zero() {
Random generator = new Random();
int r = generator.nextInt(2);
if (r == 1) {
String big = "A";
String small = "a";
return new String[] { big, small };
} else {
String big = "B";
String small = "b";
return new String[] { big, small };
}
}
Run Code Online (Sandbox Code Playgroud)
如果我运行这几次我的输出是这样的.
Aa Aa Aa Aa Bb Aa Aa Aa Bb
按顺序它并不是真的.但它几乎从未接近50/50
我不是在考虑五十五,但似乎如果首先选择"Aa",那么它将接下来大约3次,但如果首先选择Bb,那么它也将在接下来的三次被选中.
我正在尝试在已经通过monkeyrunner安装的应用程序上运行一些命令.我已经编辑了d.android.com上列出的示例代码,我将其更改为:
# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()
# Installs the Android package. Notice that this method returns a boolean, so you can test
# to see if the installation worked.
device.installPackage('myproject/bin/MyApplication.apk')
# sets a variable with the package's internal name
package = 'com.example.myTestApp'
# sets a variable with the name of an Activity in the package
# activity = …Run Code Online (Sandbox Code Playgroud) 我理解这个问题非常相似:Android上的getDir和getFilesDir有什么区别?
但是,当我只想在私人数据中保存文件时,我仍然不确定要使用什么.
对于我应该使用的目录data/data/com.test.myapp?那将使我的应用程序私有化?
// Gets the absolute path to the filesystem directory where your internal files are saved.
getFilesDir()
// Creates (or opens an existing) directory within your internal storage space.
getDir()
Run Code Online (Sandbox Code Playgroud)
我也试过阅读一些commonsware开源项目,但我想我对整体感到更加困惑,getExternalFilesDir()因为在某个api之后Android没有将内部存储(非sdcard)称为"外部"存储水平?
我不经常使用JSON,但是我在Android中执行此操作时遇到了一些麻烦而没有其他库.我用Koush标记了Ion,我想用它来检索伦敦的天气数据.我将使用的JSON api来自OpenWeather.据我所知,JSON是有效的,所以我现在卡在Android方面.我的最终目标是拥有一个报告伦敦的对象/字符串Main > temp.这是我的Android代码,但我不确定下一步该怎么做.有任何想法吗?
private void getTemperature() {
Log.d(TAG, "2");
final JsonObject json = new JsonObject();
Ion.with(this, "http://api.openweathermap.org/data/2.5/weather?q=London,uk")
.asJsonObject().setCallback(new FutureCallback<JsonObject>() {
@Override
public void onCompleted(Exception e, JsonObject result) {
// do stuff with the result or error
Log.d("TAG", "Complete");
//json = result;
}
});
}
Run Code Online (Sandbox Code Playgroud)
我的代码进入"完整"日志语句,但现在我正在尝试将结果设置为我创建的json对象,所以我取消注释//json = result,但是我在Eclipse中遇到错误.有帮助吗?我想这个方法简单地输出Main -> Temp哪个(截至目前)是284.51.
我在片段活动中运行setText命令,尝试在父活动中设置textView的文本,但它不起作用.有任何想法吗?
TextView text = (TextView) getView().findViewById(R.id.status);
text.setText("Text from a fragment");
Run Code Online (Sandbox Code Playgroud)
我在eclipse中没有收到错误,但是在运行时我得到了一个空指针异常.当然它发生在我setText的行.关于如何做到这一点的任何想法?
在下面的代码中,第一个if语句抱怨current_guy不能是a,final但第二个if语句抱怨current_guy不是最终的.我没有想法.
final int current_guy=0;
if (a.equals("bf")){
current_guy=1;
}
guy1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (current_guy==1) {
// TODO Auto-generated method stub
}
}
Run Code Online (Sandbox Code Playgroud)