Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android中的按钮不响应单击事件_Android_Button - Fatal编程技术网

Android中的按钮不响应单击事件

Android中的按钮不响应单击事件,android,button,Android,Button,我正在经历一个非常奇怪的问题,按钮没有响应点击事件。我有一个显示的对话框,当用户点击对话框中的积极按钮时,它会打开一个包含视频、文本框和按钮的布局。每当我点击布局上的按钮时,它都没有响应!请帮忙 布局文件: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id

我正在经历一个非常奇怪的问题,按钮没有响应点击事件。我有一个显示的对话框,当用户点击对话框中的积极按钮时,它会打开一个包含视频、文本框和按钮的布局。每当我点击布局上的按钮时,它都没有响应!请帮忙

布局文件:

     <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/roundedcorners"
    android:orientation="vertical"
    android:padding="0dp" >

   <LinearLayout
       android:id="@+id/video_panel"
       android:layout_width="match_parent"
       android:layout_height="175dp"
       android:layout_above="@+id/bottom_panel"
       android:layout_alignParentTop="true"
       android:layout_gravity="top"
       android:gravity="top"
       android:orientation="vertical" >

    </LinearLayout>

   <RelativeLayout
       android:id="@+id/bottom_panel"
       android:layout_width="match_parent"
       android:layout_height="70dp"
       android:layout_alignParentBottom="true"
       android:layout_alignParentLeft="true"
       android:layout_gravity="bottom"
       android:background="@color/milky_white"
       android:gravity="bottom"
       android:orientation="vertical" >

      <TextView
           android:id="@+id/agentname"
           android:layout_width="match_parent"
           android:layout_height="35dp" 
           android:background="@color/video_username"
           android:layout_alignParentTop="true"
           android:textStyle="bold"
           android:text="name"/>



       <Button
           android:id="@+id/disconn"
           android:layout_width="510dp"
           android:layout_height="37dp"
           android:layout_alignParentBottom="true"
           android:layout_alignParentRight="true"
           android:clickable="true"
           android:text="@string/disconnect" />

       </RelativeLayout>


    </RelativeLayout>

请检查您的代码,在肯定按钮的onclick方法中,您正在膨胀未在对话框上设置的新视图。。它未引用到对话框上的任何视图。您可以使用在对话框上设置的相同视图来设置侦听器。“在对话框上设置视图”与在其上设置onclick listener的视图不同。我认为问题是,您正在将onClick listener设置在onClick of Positive按钮中。所以,除非您单击对话框的正按钮,否则不会设置ClickListeneronDisconnect按钮。 尝试将onclick listener设置在断开连接按钮的onclick of positive按钮之外。如下面的示例代码所示。希望这有帮助

AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("test title");
        builder.setMessage("test message");
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.test_layout, null);
        builder.setView(view);
        Button testButton = (Button) view.findViewById(R.id.test_button);
        testButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Toast.makeText(context, "Hello", Toast.LENGTH_SHORT).show();
            };
        });
        builder.setNegativeButton("Cancel",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // Logic on negative button click
                    }
                });
        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // logic on positive button click
            }
        });
        AlertDialog dialog = builder.create();
        dialog.show();
如何在单击肯定按钮时设置onclick侦听器:


所有这些代码都应该在UI线程上运行,不能将这些代码放在运行中。相反,找到一种方法来使用

看起来问题终于解决了。对不起,我没有发布完整的代码。我将WindowManager参数从TYPE_SYSTEM_OVERLAY更改为TYPE_PHONE,它成功了。 似乎由于安全问题,TYPE_SYSTEM_OVERLAY阻止接收任何触摸事件

谢谢,
Uday

有什么反应?没有或错误?@user3659322你能不能在我调试时发布一些详细的代码,它不会进入onClick本身!。嗨,纳宾,我已经发布了更详细的代码。即使在放置断点之后,Onclick也不会返回到按钮。请帮助。我使用xml文件中列出的父布局。这是父视图。按钮在相对主义者的口袋里。谢谢桑托什。我会检查的。但是当我点击对话框上的肯定按钮时,是否应该设置聊天版面中的onClick按钮?我总是按肯定按钮。请检查您的代码,在肯定按钮的onclick方法中,您正在膨胀对话框中未设置的新视图。。它未引用到对话框上的任何视图。您可以使用在对话框上设置的相同视图来设置侦听器。对话框上设置的视图与您在单击侦听器上设置的视图不同。您能告诉我怎么做吗?同时,onClickLister在poitive按钮之外,仍然没有调用onClick:使用我发布的示例代码。。如果要将click listener设置为“仅在正按钮单击时单击”,请获取“view set on”对话框的引用并使用它。在原始答案中添加了示例代码,以显示如何在单击肯定按钮时将onclick listener设置为on按钮谢谢我这样做了,我在下一行中得到了一个异常。wm.addViewouterVideoView,参数;如何找到布局的父视图?E/AndroidRuntime16635:致命异常:主E/AndroidRuntime16635:java.lang.RuntimeException:查看android.widget.RelativeLayout{212aa410 V.E.…..正在添加ID 0,0-556617 7f0e0086 app:ID/layout_root},但它已经在android.view.view.assignParentView.java:12121上有了一个父级E/AndroidRuntime16635:at android.view.ViewRootImpl.SetViewRootImpl.java:838
AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("test title");
        builder.setMessage("test message");
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.test_layout, null);
        builder.setView(view);
        Button testButton = (Button) view.findViewById(R.id.test_button);
        testButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Toast.makeText(context, "Hello", Toast.LENGTH_SHORT).show();
            };
        });
        builder.setNegativeButton("Cancel",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // Logic on negative button click
                    }
                });
        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // logic on positive button click
            }
        });
        AlertDialog dialog = builder.create();
        dialog.show();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("test title");
        builder.setMessage("test message");
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        // This is the view we are setting on dialog. You can use only this view
        // to access view present on dialog. Using this reference, we can set
        // onclick listener in positive button's onclick event
        final View view = inflater.inflate(R.layout.test_layout, null);
        builder.setView(view);

        builder.setNegativeButton("Cancel",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // Logic on negative button click
                    }
                });
        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // logic on positive button click
                // Set onclick listener whenever positive button is clicked.
                Button testButton = (Button) view
                        .findViewById(R.id.test_button);
                testButton.setOnClickListener(new OnClickListener() {
                    public void onClick(View v) {
                        Toast.makeText(context, "Hello", Toast.LENGTH_SHORT)
                                .show();
                    };
                });
            }
        });
        AlertDialog dialog = builder.create();
        dialog.show();
 videoView = new VideoStreamsView(context, R.drawable.tech_mute, R.drawable.tech_connect);


                    LayoutInflater li = LayoutInflater.from(context);
                    outerVideoView = (RelativeLayout) li.inflate(R.layout.chat_float, null); 
                    LinearLayout vView = (LinearLayout) outerVideoView.findViewById(R.id.video_panel);

                    TextView agent_name = (TextView) outerVideoView.findViewById(R.id.agentname);
                    agent_name.setText(name);



                    //RelativeLayout bottomView = (RelativeLayout) outerVideoView.findViewById(R.id.bottom_panel);

                    Button discon_but = (Button) outerVideoView.findViewById(R.id.disconn);
                    discon_but.setClickable(true);

                    discon_but.setOnClickListener(new View.OnClickListener() 
                    {
                        @Override
                        public void onClick(View v) 
                        {
                            //System.out.println("mesh: button clicked disconnect!!");
                            Toast.makeText(context, "Video Connection disconnected", Toast.LENGTH_LONG).show();

                            outCmd.sendJsonCommand(getNodeId(), "videoChatStatus", new StatusJson("User disconnected the call.",1));
                            coord.disconnect();

                        }
                    });