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(DialogInterf开发者_Go百科ace dialog, int whichButton) {
//do nothing just dispose
}
})
.create().show();
You can also apply this theme so your activity appears like a dialog box:
<activity android:theme="@android:style/Theme.Dialog">
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.
精彩评论