Java 安卓:什么&x27;为alertdialog项编写函数的过程是什么?
我将在AlertDialog的项中编写一些函数:-代码是:-Java 安卓:什么&x27;为alertdialog项编写函数的过程是什么?,java,android,Java,Android,我将在AlertDialog的项中编写一些函数:-代码是:- final CharSequence[] items = {"Now", "Later", "Cancel"}; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("When you need to Take BackUp?"); builder.setSingleChoiceIt
final CharSequence[] items = {"Now", "Later", "Cancel"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("When you need to Take BackUp?");
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item)
{
// Toast.makeText(getApplicationContext(),items[item],Toast.LENGTH_SHORT).show();
items[0].notify();
items[1].charAt(2);
}
});
builder.show();
此项将启用某些功能,我如何声明和定义该功能。所选的
项
将被传递到方法签名中的onClick
方法中
public void onClick(DialogInterface dialog, int item) {
switch(item) {
case 0: // the first item in the CharSequence[]
callUserClickedNow();
break;
case 1: // the second item in the CharSequence[]
callUserClickedLater();
break;
case 2: // the thirditem in the CharSequence[]
callUserClickedCancel();
break;
}
dialog.dismiss();
}
然后在创建警报对话框的方法之外:
private void callUserClickedNow() {
// do stuff
}
等等。谢谢。但是,我想在CharSequence中写入每个项目(现在,稍后,取消)如何继续?您的问题是如何确定用户单击了哪个项目?或者如何基于它调用方法?是的,但我需要一个包含某个方法的项。它应该调用一个方法并操作一些东西。那么,如何为特定项声明和定义方法呢。