Thursday, July 21, 2011

[android-developers] Re: how do you add an item in a list if a user presses yes button in an alert dialog box and don't add it if he presses no

hope this will help you..

AlertDialog.Builder b = new AlertDialog.Builder(Main.this);
b.setItems(new String[]{"you", "may", "need", "to", "add"}, new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
AlertDialog.Builder bb = new AlertDialog.Builder(Main.this);
bb.setTitle("info");
bb.setMessage("Are you sure you want to add this to ur list?");
bb.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(Main.this, "Add to ur list",
Toast.LENGTH_SHORT).show();
//add to ur list
}
});

bb.setNegativeButton("No", new
DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(Main.this, "no need to add to ur list",
Toast.LENGTH_SHORT).show();
//do nothing
}
});
bb.create().show();

}
});
b.create().show();

On Jul 21, 2:31 pm, Arif Nadeem <arifnade...@gmail.com> wrote:
> Hello everyone, I am making an app in which if a user selects a
> submenu item I pop up an Alert dialog which asks his confirmation
> whether he wishes to save that item in his list and saves it if he
> presses yes and doesn't add it if he presses no.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment