How to open Activity from AlertDialog.Builder?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How to open Activity from AlertDialog.Builder?

Postby toko » Wed Dec 16, 2009 11:43 pm

Hello All,

This is my story:
I create a ListView that when clicking on certain item,
a AlertDialog.Builder dialog pop-up with list of items. so far so good.

Now, I expected that when clicking on one of the options from the dialog, ("Edit" for example)
The proper Activity (EditActivity) will rise up. The problem it's not!!

So, here is my questions:
How to open new Activity from the "onClick" method of AlertDialog.Builder?
If it's not possible,
how to return the function parameter 'item' of onClick method to the caller of this dialog?

This is my code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.      public void popdialog(){
  2.  
  3.  
  4.  
  5.             AlertDialog.Builder builder = new AlertDialog.Builder(this);
  6.  
  7.             builder.setTitle("My contact");
  8.  
  9.             builder.setItems(items, new DialogInterface.OnClickListener() {
  10.  
  11.                 public void onClick(DialogInterface dialog, int item)
  12.  
  13.                {
  14.  
  15.                     if(item == 0)  // edit contact
  16.  
  17.                     {
  18.  
  19.                           // here i want to call to next Activity
  20.  
  21.                           Intent i = new Intent(this, EditActivity.class);
  22.  
  23.                           startActivityForResult(i, 1);
  24.  
  25.                      }
  26.  
  27.                    dialog.dismiss();
  28.  
  29.                 }
  30.  
  31.             });
  32.  
  33.             AlertDialog alert = builder.create();
  34.  
  35.             alert.show();
  36.  
  37.             }
  38.  
  39. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
toko
Freshman
Freshman
 
Posts: 6
Joined: Sun Dec 13, 2009 5:55 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 3 guests