Ete*_*ner 4 android android-dialog
我创建了一个通用的OkCancelDialog类,可以通过静态方法在我的应用程序中方便地调用它:
static public void Prompt(String title, String message) {
OkCancelDialog okcancelDialog = new OkCancelDialog();
okcancelDialog.showAlert(title, message);
}
Run Code Online (Sandbox Code Playgroud)
由于各种原因,我需要活动中的onClick监听器,所以在我的活动中:
public void onClick(DialogInterface v, int buttonId) {
if (buttonId == DialogInterface.BUTTON_POSITIVE) { // OK button
// do the OK thing
}
else if (buttonId == DialogInterface.BUTTON_NEGATIVE) { // CANCEL button
// do the Cancel thing
}
else {
// should never happen
}
}
Run Code Online (Sandbox Code Playgroud)
这适用于应用程序中的单个对话框,但现在我想添加另一个确定/取消对话框,由同一活动处理.据我所知,只有一个onClick()可以为活动定义,所以我不知道如何实现这个.
有什么建议或提示吗?
尝试这样的事......
public class MyActivity extends Activity
implements DialogInterface.OnClickListener {
// Declare dialogs as Activity members
AlertDialog dialogX = null;
AlertDialog dialogY = null;
...
@Override
public void onClick(DialogInterface dialog, int which) {
if (dialogX != null) {
if (dialogX.equals(dialog)) {
// Process result for dialogX
}
}
if (dialogY != null) {
if (dialogY.equals(dialog)) {
// Process result for dialogY
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
编辑这是我创建我AlertDialogs...的方式
private void createGuideViewChooserDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select Guide View")
.setSingleChoiceItems(guideViewChooserDialogItems, currentGuideView, this)
.setPositiveButton("OK", this)
.setNegativeButton("Cancel", this);
guideViewChooserDialog = builder.create();
guideViewChooserDialog.show();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1709 次 |
| 最近记录: |