简体   繁体   English

在Android的警报对话框中打开活动

[英]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. 我有main.class-有一个按钮-单击按钮会到达list.class(此列表oncreate会获取db的所有值并显示(使用了async)),但这以全屏显示。

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. 无需调用其他活动,只需在该Alert中创建一个alertdialog do setContentView即可。

    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. 您可以将AlertDialog.Builder与setSingleChoiceItems方法一起使用来设置项目。

http://developer.android.com/reference/android/app/AlertDialog.Builder.html 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. 并在活动类中的setContentView之前调用requestWindowFeature(Window.FEATURE_NO_TITLE) ,您的活动将显示为警报对话框。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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