views:

1257

answers:

3

I want to start activity inside popup screen suggest any quick change ??

new AlertDialog.Builder(SearchResults.this)
       .setTitle("Refine") 
       .setItems(/*catNames*/, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
         /* User clicked so do some stuff */
         String catName = catNames[which];
         String categoryIds = subCats.get(catName);
       }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
         //do nothing just dispose
        }
       })
       .create().show();
+1  A: 

Hi!
If all you want to do is to start activity when user choose an item from your dialog, you can do it like this:

new AlertDialog.Builder(SearchResults.this)
                    .setTitle("Refine") 
                    .setItems(/*catNames*/, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                    /* User clicked so do some stuff */
                                    String catName = catNames[which];
                                    String categoryIds = subCats.get(catName);
                                    Intent intent = new Intent(SearchResults.this,YourActivity.class);
                                    startActivity(intent);
                    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                    //do nothing just dispose
                            }
                    })
                    .create().show();

In your onClick() method you create an intent and pass it to startActivity() method.

Ramps
I want to use intent as a view of the dialog.
Faisal khan
Hmmm, I'm little bit confused here. Intent is an operation to be performed - it's not a View/ViewGroup component so it can't be used as a layout of a dialog. One of the operations that can be performed by intent is to start new activity - so maybe you want to set your custom layout for a dialog? Is that the case?
Ramps
+2  A: 

You can also apply this theme so your activity appears like a dialog box:

<activity android:theme="@android:style/Theme.Dialog">
James
A: 

Thanks James! Sorry, I can't vote on you. No reputation points :S

this should be a comment...
Janusz