0

如何在单击基本适配器的列表项时打开自定义对话框?

我尝试使用代码通过单击项目列表来打开“自定义”对话框,但得到了 windowmanager 的错误

 public void onItemClick(AdapterView<?> arg0, View view, int position,
                long arg3) {

            int childPosition = ExpandableListView.getPackedPositionChild(position);
            int tempID = childPosition;
            Log.i("tempID",""+tempID);
            Log.i("Item Clicked","Position"+position);


            //Log.i("Item Clicked","Position"+position);    

            type_dilog = new Dialog(Contacts.this);
            type_dilog.setContentView(R.layout.dialogg);

            type_dilog.setTitle(" Select the Operation ");
            Log.i("3333333333","333333333");
            TextView alert_messagee = (TextView) type_dilog.findViewById(R.id.dilog_messagee);
            alert_messagee.setVisibility(View.GONE);
            imageBtn = (Button) type_dilog.findViewById(R.id.automessage_btn);
            videoBtn = (Button) type_dilog.findViewById(R.id.ownmessage_btn);
            captuerimageBtn = (Button) type_dilog.findViewById(R.id.captureimage_btn);
            takevideoBtn = (Button) type_dilog.findViewById(R.id.takevideo_btn);
            delete = (Button) type_dilog.findViewById(R.id.delete_btn);
//              delete_no = (Button) type_dilog.findViewById(R.id.delete_no_btn);
            Log.i("44444444","4444444444");
            imageBtn.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT));
            videoBtn.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT));
            captuerimageBtn.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT));
            takevideoBtn.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT));
            delete.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT));

            delete.setVisibility(View.GONE);

            imageBtn.setText("Photo Library");
            videoBtn.setText("Video Library");
            captuerimageBtn.setText("Take Picture");
            takevideoBtn.setText("Take Video");


            type_dilog.show();

}





02-25 17:09:55.040: E/AndroidRuntime(27697): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@41d9af60 is not valid; is your activity running?

02-25 17:09:55.040: E/AndroidRuntime(27697): 在 android.view.ViewRootImpl.setView(ViewRootImpl.java:683) 02-25 17:09:55.040: E/AndroidRuntime(27697): 在 android. view.WindowManagerImpl.addView(WindowManagerImpl.java:301) 02-25 17:09:55.040: E/AndroidRuntime(27697): 在 android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215) 02-25 17:09: 55.040: E/AndroidRuntime(27697): 在 android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140) 02-25 17:09:55.040: E/AndroidRuntime(27697): 在 android.view.Window$LocalWindowManager .addView(Window.java:537) 02-25 17:09:55.040: E/AndroidRuntime(27697): 在 android.app.Dialog.show(Dialog.java:278) 02-25 17:09:55.040: E /AndroidRuntime(27697): 在 dev.zoemultiline.Contacts$ContactsAdapter$1.onClick(Contacts.java:311) 02-25 17:09:55.040: E/AndroidRuntime(27697):在 android.view.View.performClick(View.java:3567) 02-25 17:09:55.040: E/AndroidRuntime(27697): 在 android.view.View$PerformClick.run(View.java:14224) 02- 25 17:09:55.040: E/AndroidRuntime(27697): 在 android.os.Handler.handleCallback(Handler.java:605) 02-25 17:09:55.040: E/AndroidRuntime(27697): 在 android.os。 Handler.dispatchMessage(Handler.java:92) 02-25 17:09:55.040: E/AndroidRuntime(27697): 在 android.os.Looper.loop(Looper.java:137) 02-25 17:09:55.040: E/AndroidRuntime(27697): 在 android.app.ActivityThread.main(ActivityThread.java:4517) 02-25 17:09:55.040: E/AndroidRuntime(27697): 在 java.lang.reflect.Method.invokeNative(Native方法) 02-25 17:09:55.040: E/AndroidRuntime(27697): at java.lang.reflect.Method.invoke(Method.java:511) 02-25 17:09:55.040: E/AndroidRuntime(27697) : 在 com.android.internal.os。ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993) 02-25 17:09:55.040: E/AndroidRuntime(27697): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760) 02-25 17:09:55.040:E/AndroidRuntime(27697):在 dalvik.system.NativeStart.main(本机方法)

上面是想要打开自定义对话框时单击 onItemClick 时出现的 Log cat 错误

我写 type_dilog = new Dialog(getParent()); 而不是 type_dilog = new Dialog(Contacts.this); 它解决了我的问题

4

1 回答 1

-1

实施 onitemselectedlistener 以获得更好的结果来解决您的问题。

于 2013-02-25T10:39:12.533 回答