简体   繁体   中英

Open an activity inside an alert dialog box in android

Can I trigger an activity inside an alert box?

Here is what I am trying out: I have list of items in DB.

I have main.class - which has a button - on click on the button it gets to list.class (This list oncreate gets and all values of db and displays (async is used)) but this is shown in full screen.

Instead I want to show the list of fetched items in a alert dialog instead of showing it in full screen? Is this possible?

Let me know!

Thanks!

Instead of calling another activity just create an alertdialog an do setContentView in that Alert.

    AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
    alertbox.setCancelable(false);
    alertbox.setMessage(message).setPositiveButton("OK",
            new OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
    AlertDialog al = alertbox.create();
    LayoutInflater li = ((Activity)context).getLayoutInflater();
    View v = li.inflate(you_layout_resource_id, null);
    al.setContentView(v);
    al.show();

hope this helps

You won't create an activity inside a dialog but you need to build a dialog with the list of your items. You can use AlertDialog.Builder with setSingleChoiceItems method to set your items.

http://developer.android.com/reference/android/app/AlertDialog.Builder.html

It seems that you cannot. You may use the "handle" to finish this.

You mean you want to show your activity in a alert dialog instead of an activity/page.

It's simple if is that what you are looking for. Just add

android:theme="@android:style/Theme.Dialog"

in your manifest file for the corresponding activity(list activity). And call requestWindowFeature(Window.FEATURE_NO_TITLE) before setContentView in your activity class, your activity will be displayed as an alert dialog.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM