如果用户已经按下该按钮,我需要停止显示AlertDialog (即在OnCreate中)。如果已经单击了“正”按钮,我需要禁用AlertDialog。
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
dlgAlert.setMessage(getString(R.string.dialogMSG));
dlgAlert.setTitle("App Support Checker");
dlgAlert.setPositiveButton(R.string.yesdev,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
dlgAlert.setCancelable(false);
dlgAlert.create().show();发布于 2013-08-06 01:39:47
你的意思是说在按正键时,你需要删除对话框?顺便说一句,您可以调用式微() api for对话框来删除该对话框。
若要获取共享首选项,请在活动中使用以下方法:
SharedPreferences prefs = this.getSharedPreferences( "com.example.app", Context.MODE_PRIVATE); 若要读取首选项:
String dateTimeKey = "com.example.app.datetime";
long l = prefs.getLong(dateTimeKey, new Date().getTime()); 编辑和保存首选项
Date dt = getSomeDate();
prefs.edit().putLong(dateTimeKey, dt.getTime()).commit();android的示例目录示例检索和存储共享首选项。它位于:/samples/android-/ApiDemo目录中。
若要将值存储在共享首选项中:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("Name","Sushil");
editor.commit(); 要从共享首选项检索值,请执行以下操作:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String name = preferences.getString("Name","");
if(!name.equalsIgnoreCase("")) {
name = name+" Jha"; /* Edit the value here*/
} 这是处理您正在讨论的场景的正确和最好的方法。
发布于 2013-08-06 01:26:11
你得把它指向别的地方,我是说其他的活动。否则,您可以使用setNegativeButton而不是setPositiveButton。
dlgAlert.setNegativeButton(R.string.yesdev,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});干杯,
https://stackoverflow.com/questions/18070369
复制相似问题