Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android activity inside dialog

I want to start an activity inside a pop-up screen. Are there any suggestions for a 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();
like image 891
d-man Avatar asked Dec 18 '09 05:12

d-man


2 Answers

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

<activity android:theme="@android:style/Theme.Dialog">
like image 75
James Avatar answered Oct 25 '22 19:10

James


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.

like image 32
Ramps Avatar answered Oct 25 '22 20:10

Ramps