如何在單擊基本適配器的列表項目時打開自定義對話框?單擊列表視圖時打開自定義對話框
我使用的代碼,點擊項目列表上打開自定義對話框,但得到的窗口管理器的東西錯誤
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 [email protected] is not valid; is your activity running?
02-25 17試過:09:55.040:E/AndroidRuntime(27697) :at android.view.ViewRootImpl.setView(ViewRootImpl.java:683) 02-25 17:09:55.040:E/AndroidRuntime(27697):at 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):at android。 view.WindowManagerImpl $ CompatModeWrapper。 addView(WindowManagerImpl.java:140) 02-25 17:09:55.040:E/AndroidRuntime(27697):at android.view.Window $ LocalWindowManager.addView(Window.java:537) 02-25 17:09: 55.040:E/AndroidRuntime(27697):at 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):at android.view.View.performClick(View.java:3567) 02-25 17:09:55.040 :E/AndroidRuntime(27697):at android.view.View $ PerformClick.run(View.java:14224) 02-25 17:09:55.040:E/AndroidRuntime(27697):at android.os.Handler.handleCallback (Handler.java:605) 02-25 17:09:55.040:E/AndroidRuntime(27697):at android.os.Handler.dispatchMessage(Handler.java:92) 02-25 17:09:55.040:E/AndroidRuntime(27697):at android.os.Looper.loop(Looper.java:137) 02-25 17:09:55.040:E/AndroidRuntime(27697):at 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時出現的日誌貓錯誤
我編寫了type_dilog = new Dialog(getParent());而不是type_dilog = new Dialog(Contacts.this);它解決了我的問題
ru使用fragnebts – Sush 2014-01-04 03:49:26