How do I open the Custom dialog on clicking the List Item of base adapter?
I tried using the code for opening the Custom dialog by clicking on the item list ,but getting the error of windowmanager something
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): 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): at 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)
Above is the Log cat error coming on the click of onItemClick when want to opening the Custom dialog
I write type_dilog = new Dialog(getParent()); instead of type_dilog = new Dialog(Contacts.this); and it solves my problem