如何在单击基本适配器的列表项目时打开自定义对话框?
我尝试使用代码打开自定义对话框,方法是单击项目列表,但是得到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):at 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):at java.lang.reflect.Method.invokeNative(Native Method) 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):at 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):at dalvik.system.NativeStart.main(Native Method)
上面是想要打开自定义对话框
时点击onItemClick时出现的Log cat错误我写了type_dilog = new Dialog(getParent());而不是type_dilog = new Dialog(Contacts.this);它解决了我的问题
答案 0 :(得分:-1)
实施onitemselectedlistener,以便更好地解决您的问题。