简体   繁体   English

如何在android的多个标签小部件中显示自定义警报对话框?

[英]How to display customized alert dialog within multiple tab widgets in android?

I have to create customized alert in my android application.我必须在我的 android 应用程序中创建自定义警报。 And this is my page这是我的页面

在此处输入图片说明

I have created 4 main tabs and two subtabs within my tab widget.我在选项卡小部件中创建了 4 个主选项卡和两个子选项卡。 pnr status is my first tab first page. pnr status 是我的第一个标签页。 Within that i have created customized list view.在其中我创建了自定义列表视图。 When i clicked my list view I have to show my customized alert view .当我单击我的列表视图时,我必须显示我自定义的警报视图。 I can create my customized alert.我可以创建我的自定义警报。 My code is here.我的代码在这里。 http://pastie.org/8366400 http://pastie.org/8366400

Now my issue is When i click the list view content it shows some error my errors are http://pastie.org/8366406 .现在我的问题是当我单击列表视图内容时,它显示一些错误我的错误是http://pastie.org/8366406

My launcher activty have four tabs.我的启动器活动有四个选项卡。 which means main actiivty.这意味着主要活动。 Then my first tab content is pnr status and schedule .然后我的第一个标签内容是 pnr status 和 schedule 。 So my pnr status will be shown first when i opened my application.所以当我打开我的应用程序时,我的 pnr 状态将首先显示。 But I tired some other way and found some thing.但我以另一种方式累了,找到了一些东西。 When i give my pnrstatus activity as launcher activty means my coustomized alert would shown.当我将我的 pnrstatus 活动作为启动器活动时,意味着会显示我自定义的警报。 In the means time when i give my maintab actiivty as launcher it won't come.同时,当我将 maintab 活动作为启动器时,它不会出现。 Now my question is If we are using tabwidget within tabwidget means our is alert won't come?现在我的问题是如果我们在 tabwidget 中使用 tabwidget 意味着我们的警报不会出现? Can any body help me to resolve this issue?任何机构都可以帮助我解决这个问题吗?

Use getParent() instead of context使用getParent()而不是上下文

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getParent());

refer Android dialogs are causing android.view.WindowManager$BadTokenException: Unable to add window参考Android 对话框导致 android.view.WindowManager$BadTokenException: Unable to add window

Try this, You can create your own xml file.试试这个,您可以创建自己的 xml 文件。 setContentView this method you can set your customview. setContentView这个方法你可以设置你的自定义视图。

final Dialog dialog = new Dialog(YourActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Add your lyout        
dialog.setContentView(R.layout.Yourlayout);
dialog.setCancelable(true);
// Declare your view here       
// Do your stuff here           
dialog.show();

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

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