1

I am trying to open a custom dialog box that cover the full interface of the device .But I don't know it is throwing exception Please check my code and help me to solve this issue.

On click of the listview item

data.setOnItemClickListener(new OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
                passengerInformationPopup();

              }
    });

**The Function to open the Dialog**



public void passengerInformationPopup() {
    final Dialog dialog= new Dialog(getBaseContext());
    dialog.setContentView(R.layout.passenger_details_dialog); 
    String[] tittlearray ={"Mr.","Mrs.","Ms"};
    Spinner tittleSpinner = (Spinner) dialog.findViewById(R.id.Tittle);
        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, tittlearray); 

    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
    tittleSpinner.setAdapter(dataAdapter);
    dialog.show();
}

Exception

08-14 16:39:50.338: E/AndroidRuntime(30294): FATAL EXCEPTION: main
08-14 16:39:50.338: E/AndroidRuntime(30294): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
08-14 16:39:50.338: E/AndroidRuntime(30294):    at android.view.ViewRootImpl.setView(ViewRootImpl.java:656)
08-14 16:39:50.338: E/AndroidRuntime(30294):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:328)
08-14 16:39:50.338: E/AndroidRuntime(30294):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:226)
08-14 16:39:50.338: E/AndroidRuntime(30294):    at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:151)
08-14 16:39:50.338: E/AndroidRuntime(30294):    at android.app.Dialog.show(Dialog.java:277)
08-14 16:39:50.338: E/AndroidRuntime(30294):    at com.example.userdetails.MainActivity.passengerInformationPopup(MainActivity.java:181)
08-14 16:39:50.338: E/AndroidRuntime(30294):    at com.example.userdetails.MainActivity$5.onItemClick(MainActivity.java:149)
08-14 16:39:50.338: E/AndroidRuntime(30294):    at android.widget.AdapterView.performItemClick(AdapterView.java:298)
08-14 16:39:50.338: E/AndroidRuntime(30294):    at android.widget.AbsListView.performItemClick(AbsListView.java:1114)
08-14 16:39:50.338: E/AndroidRuntime(30294):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:2937)
08-14 16:39:50.338: E/AndroidRuntime(30294):    at android.widget.AbsListView$1.run(AbsListView.java:3695)
08-14 16:39:50.338: E/AndroidRuntime(30294):    at android.os.Handler.handleCallback(Handler.java:615)
08-14 16:39:50.338: E/AndroidRuntime(30294):    at android.os.Handler.dispatchMessage(Handler.java:92)
08-14 16:39:50.338: E/AndroidRuntime(30294):    at android.os.Looper.loop(Looper.java:153)
08-14 16:39:50.338: E/AndroidRuntime(30294):    at android.app.ActivityThread.main(ActivityThread.java:4987)
08-14 16:39:50.338: E/AndroidRuntime(30294):    at java.lang.reflect.Method.invokeNative(Native Method)
08-14 16:39:50.338: E/AndroidRuntime(30294):    at java.lang.reflect.Method.invoke(Method.java:511)
08-14 16:39:50.338: E/AndroidRuntime(30294):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
08-14 16:39:50.338: E/AndroidRuntime(30294):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
08-14 16:39:50.338: E/AndroidRuntime(30294):    at dalvik.system.NativeStart.main(Native Method)
4

3 回答 3

1

利用

final Dialog dialog= new Dialog(getApplicationcontext()); OR  final Dialog dialog= new Dialog(YOUR_ACTIVITY.this);

代替

final Dialog dialog= new Dialog(getBaseContext());
于 2013-08-14T11:17:04.227 回答
1

使用活动上下文

     final Dialog dialog= new Dialog(ActivityName.this);

了解何时使用活动上下文

何时调用活动上下文或应用程序上下文?

从评论中

如何设置对话框以全屏显示?

编辑:

来自 Dianne Hackborn 的建议

给它的构造函数一个非对话框主题,例如android.R.style.Themeor android.R.style.Theme_Light

看@主题

https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/themes.xml

更多信息 @

https://groups.google.com/forum/#!topic/android-developers/NDFo9pF8sHY

   Dialog dialog=new Dialog(ActivityName.this,android.R.style.Theme);
于 2013-08-14T11:23:33.733 回答
0

尝试这个

final Dialog dialog= new Dialog(YOUR_ACTIVITY.this);

代替

final Dialog dialog= new Dialog(getBaseContext());
于 2013-08-14T11:23:14.183 回答