android : what's the procedure to write functions for alertdialog item?
I'm going to write s开发者_StackOverflow中文版ome function in AlertDialog's item : - Code is : -
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();
This item will enable some function, how can i declare and define that.
The item
that is selected will be passed into the onClick
method, the int item
in the method's signature.
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();
}
Then outside of the method where you create the AlertDialog
:
private void callUserClickedNow() {
// do stuff
}
etc...
精彩评论