【问题标题】:opening of the custom dialog on the click of list view单击列表视图打开自定义对话框
【发布时间】:2013-02-25 10:35:16
【问题描述】:

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

我尝试使用代码通过单击项目列表打开自定义对话框,但得到窗口管理器的错误

 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): 在 java.lang.reflect.Method.invokeNative(Native Method) 02-25 17:09:55.040: E/AndroidRuntime(27697): 在 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): 在 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);它解决了我的问题

【问题讨论】:

    标签: java android


    【解决方案1】:

    实现 onitemselectedlistener 以获得更好的结果。

    【讨论】:

    • 它将如何解决他的问题?他有没有提到他正在使用 Spinner?
    • 我正在使用基本适配器,onitemclick,我能够获取值或位置但无法打开对话框
    • onitemselectedlistener 对我没有帮助,我正在获取设备中所有联系人的列表
    • 我已尽一切努力在自定义拨号上显示详细信息,但无法做到,请帮我这样做
    • 我写 type_dilog = new Dialog(getparent());而不是 type_dilog = new Dialog(Contacts.this);它解决了问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-09
    相关资源
    最近更新 更多