【发布时间】:2013-11-20 20:48:26
【问题描述】:
在我的代码中,当我选择 if-elseIf 语句中提到的选项时,我想立即关闭警报对话框并开始活动。我不想要确定和取消按钮。我的代码工作正常(if 语句中的语句有效,但警报对话仍然存在)。感谢您的帮助
final AlertDialog.Builder builder =
new AlertDialog.Builder(arg0.getContext());
builder.setTitle("Favourities Management");
// TODO Auto-generated method stub
int selected = 0;
builder.setSingleChoiceItems(values, selected, new DialogInterface.OnClickListener() {
@
Override
public void onClick(DialogInterface dialog, int which) {
if (values[which] == "Select Benificiary") {
Intent registerUser = new Intent(FinalUtilityBillPayment.this, ListViewBeneficiaryBillPayment.class);
FinalUtilityBillPayment.this.startActivity(registerUser);
startActivityForResult(registerUser, 1);
} else if (values[which] == "Add Benificiary") {
try {
mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE, null);
mydb.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE + " (ID INTEGER PRIMARY KEY, ReferenceNo TEXT, Mobile Text);");
mydb.close();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Error in creating table", Toast.LENGTH_LONG).show();
}
try {
mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE, null);
mydb.execSQL("INSERT INTO " + TABLE + "(ReferenceNo, Mobile) VALUES('" + ref.getText().toString() + "','" + mob.getText().toString() + "')");
mydb.close();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Error in inserting into table", Toast.LENGTH_LONG).show();
}
} else if (values[which] == "Delete Benificiary") {
Intent registerUser = new Intent(FinalUtilityBillPayment.this, ListViewDeleteBeneficiaryBillPayment.class);
//startActivityForResult(registerUser, 1);
FinalUtilityBillPayment.this.startActivity(registerUser);
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
【问题讨论】:
-
如果你不想确定和取消按钮,那么你为什么要使用警报对话框?
-
dismiss 不起作用...我想弹出选项以在单击时选择..还有其他选项吗??
-
您可以使用
popupWindow。参考developer.android.com/reference/android/widget/PopupWindow.html