Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.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:onClickListener for ImageButton_Android_Imagebutton_Onclicklistener - Fatal编程技术网

Android:onClickListener for ImageButton

Android:onClickListener for ImageButton,android,imagebutton,onclicklistener,Android,Imagebutton,Onclicklistener,我有一个按钮。当我点击ImageButton时。它使父布局顶部的另一个布局(childLayout)可见android:id=“@+id/mainLayout”。现在childLayout有三个按钮(后退、呼叫、Web)。我为Back、Call和Web按钮实现了OnClickListeners。但当我点击“Back”按钮时,它并没有触发事件。但是,当我双击按钮时,它就起作用了。为什么OnClickListener不能在单击时工作 @Override

我有一个按钮。当我点击ImageButton时。它使父布局顶部的另一个布局(childLayout)可见android:id=“@+id/mainLayout”。现在childLayout有三个按钮(后退、呼叫、Web)。我为Back、Call和Web按钮实现了OnClickListeners。但当我点击“Back”按钮时,它并没有触发事件。但是,当我双击按钮时,它就起作用了。为什么OnClickListener不能在单击时工作

         @Override
                public void onSingleTapConfirmed() {
                    childLayout = (LinearLayout) findViewById(R.id.childView);
                    childLayout.setVisibility(View.VISIBLE);
                    backButton = (Button)findViewById(R.id.back);
                    web = (ImageButton) findViewById(R.id.web);
                    call = (ImageButton) findViewById(R.id.call);
                    backButton.setOnClickListener(backButtonListener);
                    call.setOnClickListener(callListener);
                    web.setOnClickListener(webListener);
                }

            OnClickListener callListener = new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            Intent callIntent = new Intent(Intent.ACTION_CALL);
                            callIntent.setData(Uri.parse("tel:415-817-9955,’10"));
                            startActivity(callIntent);                  
                        }
                    };

            OnClickListener webListener = new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            Intent web = new Intent(Intent.ACTION_VIEW);
                            Uri u = Uri.parse("http://google.com");
                            web.setData(u);
                            startActivity(web);
                        }
                    };  
             OnClickListener backButtonListener = new OnClickListener() {

                @Override
                public void onClick(View v) {
                    finish();
                }
            };
和我的xml文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >


    <LinearLayout
        android:id="@+id/childView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/nav_bar"
        android:padding="5dp"
        android:visibility="gone" >

        <Button
            android:id="@+id/back"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="@drawable/title_btn"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:text="Business"
            android:textColor="@color/white" >
        </Button>

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:gravity="center"
            android:text="Image"
            android:textStyle="bold" />

        <ImageButton
            android:id="@+id/call"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/phone" />

        <ImageButton
            android:id="@+id/web"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/web" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </LinearLayout>

</LinearLayout>


或者我应该使用其他方法在imageButton的单点击事件上显示子布局。提前谢谢

有一个布尔值,在第一次单击时将其设置为真,如果用户再次单击,请检查布尔值是否为真,然后在双击中执行您想要执行的操作

您可以定义一个时间,假设用户在中再次单击30毫秒,您可以在双击中执行您想要执行的操作,否则您可以执行单键单击操作

但在安卓系统中,我们做的是单键点击和长按,长按可以取代双击。甚至建议长按,而不是双击


这里也有同样的问题,请参见链接>>

向我们展示xml?描述不太清楚,我不知道你说的“双击”是什么意思。是否先按图像按钮(第一次单击),然后按三个按钮之一(“双击”)?或者你的意思是你必须以某种方式点击三个按钮中的一个两次?