0

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.

Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148
Arif
  • 9
  • 1
  • 1
    Have a look at this question - it describes exactly what you need: http://stackoverflow.com/questions/5953644/how-can-i-get-the-results-from-an-alertdialog – Aleks G Jul 21 '11 at 15:46
  • 2
    Please show us the code you have written so far. We'll be able to better help you if you can show us exactly the point at which you are having difficulties. – Marc Bernstein Jul 21 '11 at 15:47

2 Answers2

1

You can use this to show alert:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Are you sure to do this?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    doSomeThing();
                                            dialog.cancel();
                }
            }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
Onuray Sahin
  • 4,093
  • 4
  • 33
  • 34
0

You add the element you get from the dialog to the ArrayList you use to feed your Adapter then feed the cursor = new yourAdapter(YourClass.this.getBaseContext(), android.R.layout.simple_list_item_1, dataList);

Call cursor.notifyDataSetChanged(); which tells the list to repopulate with the new data;

Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148
  • This is WAY overcomplicated for what he needs. All that's required is to get the result from an AlertDialog – Aleks G Jul 21 '11 at 15:49