Android ImageButton不工作

Android ImageButton不工作,android,imagebutton,Android,Imagebutton,这是我的布局: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/white" &g

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/white" >

    <ImageButton
        android:id="@+id/one_button"
        android:layout_width="125dp"
        android:layout_height="125dp"
        android:layout_alignParentRight="true"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"
        android:background="@drawable/1"
        android:contentDescription="@string/by1" />

    <ImageButton
        android:id="@+id/two_button"
        android:layout_width="125dp"
        android:layout_height="125dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:background="@drawable/2"
        android:contentDescription="@string/by2" />

    <ImageButton
        android:id="@+id/three_button"
        android:layout_width="125dp"
        android:layout_height="125dp"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="185dp"
        android:background="@drawable/3"
        android:contentDescription="@string/by3" />

    <ImageButton
        android:id="@+id/four_button"
        android:layout_width="125dp"
        android:layout_height="125dp"
        android:layout_alignParentRight="true"
        android:layout_marginRight="20dp"
        android:layout_marginTop="185dp"
        android:background="@drawable/4"
        android:contentDescription="@string/by4" />

</RelativeLayout>
现在,如果我按
one_按钮
two_按钮
所有功能都正常,但如果我按
three_按钮
什么都没有发生

我做错了什么

附加说明-清单正常,因为
two_按钮
启动所需的活动

谢谢


favolas

按钮名称不能以数字开头

尝试将
按钮ID
更改为
按钮1
,而不是
1按钮

它会起作用的


可能是您没有在第三个按钮上添加侦听器…

是否已在3\u按钮上设置了onClickListener

ImageButton btn=(ImageButton)findViewById(R.id.3_button);
btn.setOnClickListener(this);

我很惊讶地看到,您的前两个按钮都正常工作,这应该会引发编译错误,因为按钮ID不能以数字开头。这只是个例子。编辑我的问题。没有收到编译器错误甚至没有警告您是否已将onClickListener指定给第三个按钮?@Favolas:但如果我按三个按钮,则不会发生任何事情。方法你想在三个按钮上做什么试着在三个按钮上干杯click@PareshMayani对我已经做到了。如果按钮2起作用,并且如果按钮3发送到同一活动,则它也应起作用。只是举个例子。编辑了我的问题是的。公共类MyClass扩展活动实现OnClickListenerThank。忘了这么做:(很简单,但有时候,应该在你眼前的东西往往是看不见的。
ImageButton btn=(ImageButton)findViewById(R.id.3_button);
btn.setOnClickListener(this);