0

我有一个图像按钮。当我单击 ImageButton 时。它使父布局 android:id="@+id/mainLayout" 顶部的另一个布局(childLayout)可见。现在 ChildLayout 有三个按钮(返回、调用、Web)。我为返回、呼叫和 Web 按钮实现了 OnClickListeners。但是当我单击“返回”按钮时,它没有触发事件。但是当我双击按钮时 OnClickListener 工作。为什么 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 的单击事件上显示子布局。提前致谢。

4

1 回答 1

1

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

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

但是在Android中我们做单击和长按/长按,长按可以代替双击的东西。甚至建议长按而不是双击。

这是之前提出的相同答案,请参阅链接>>这里

于 2012-07-11T05:30:28.173 回答