我正在尝试以编程方式将一组RadioButtons添加到RadioGroup,如下所示:
for (int i = 0; i < RANGE; i++) {
RadioButton button = new RadioButton(this);
button.setId(i);
button.setText(Integer.toString(i));
button.setChecked(i == currentHours); // Select button with same index as currently selected number of hours
button.setButtonDrawable(Color.TRANSPARENT);
button.setBackgroundResource(R.drawable.selector);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
((RadioGroup)view.getParent()).check(view.getId());
currentHours = view.getId();
}
});
radioGroupChild.addView(button);
}
Run Code Online (Sandbox Code Playgroud)
我需要将drawable按钮设置为null(我只想在我的背景上添加文本).在XML中手动执行此操作android:button="@null"
非常好,但我不想对每个单选按钮进行硬编码.我尝试过这样做,button.setButtonDrawable(null)
但它没有改变任何东西.
任何帮助是极大的赞赏!
我是Android编程(以及Eclipse IDE和Android模拟器)的新手.我有Hello World和一些Notepad工作,但我仍然经常收到很多关于无法为调试器绑定本地的DDMS控制台日志消息(如下所示).
[2010-05-29 21:03:16 - ddms] Can't bind to local 8601 for debugger
[2010-05-29 21:05:26 - Device] Failed to delete temporary package: device (emulator-5556) request rejected: device not found
[2010-05-29 21:06:47 - ddms] Can't bind to local 8600 for debugger
[2010-05-29 21:07:05 - ddms] Can't bind to local 8601 for debugger
[2010-05-29 21:07:05 - ddms] Can't bind to local 8602 for debugger
Run Code Online (Sandbox Code Playgroud)
等等.这是一个问题吗?我可以以某种方式摆脱这些消息吗?
我有一个应用程序,我在其中存储用户首选项,如下所示:
public static final String KEY_PREFS_LOGIN_INFO = "login_info";
public static final String KEY_PREFS_FILE_VERSIONs = "file_versions";
public static final String KEY_PREFS_LOGS = "logs";
public static final String KEY_PREFS_OTHERS = "others";
Run Code Online (Sandbox Code Playgroud)
使用这样的特定于偏好的方法:
public static void setFileVersion(String key) {
SharedPreferences settings = getAppContext().getSharedPreferences(KEY_PREFS_FILE_VERSIONS, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("current", key);
editor.commit();
}
Run Code Online (Sandbox Code Playgroud)
然后像这样检索值:
public static String filesVersion() {
SharedPreferences settings = getAppContext().getSharedPreferences(KEY_PREFS_FILE_VERSIONS, 0);
String current = settings.getString("current", "");
return current;
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是将我的所有首选项存储在一个位置,这样我就可以使用通用方法来访问它们中的任何一个。如何在升级时设置将值从旧存储位置迁移到新存储位置的方法?我正在寻找类似于 SQLiteOpenHelper 中的 onUpgrade() 方法的东西。