Java 无法单击图像按钮

Java 无法单击图像按钮,java,android,imagebutton,Java,Android,Imagebutton,我在main_view.xml中有一个如下布局,其中包含一个ImageButton,当我单击/触摸按钮时,ButtonListener函数永远不会被调用 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/relativeLayoutFragment" android:l

我在
main_view.xml
中有一个如下布局,其中包含一个
ImageButton
,当我单击/触摸按钮时,
ButtonListener
函数永远不会被调用

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

<fragment
    android:id="@+id/mapArea"
    android:name="com.google.android.gms.maps.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</fragment>

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/locate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="10dp"
        android:background="#80000000"
        android:gravity="center"
        android:padding="10dp"
        android:text="@string/findingLocation"
        android:textColor="#FFFFFF"
        android:textSize="12sp" />

    <ImageButton
        android:id="@+id/Button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="@dimen/rightLeftMargin"
        android:layout_marginLeft="@dimen/rightLeftMargin"
        android:background="@null"
        android:clickable="true"
        android:contentDescription="@string/button1text"
        android:src="@drawable/ic_feed_active" />

    <ImageButton
        android:id="@+id/Button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="@dimen/rightLeftMargin"
        android:background="@null"
        android:contentDescription="@string/button2"
        android:src="@drawable/ic_button2" />

    <ImageButton
        android:id="@+id/Button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="@dimen/rightLeftMargin"
        android:layout_marginRight="@dimen/rightLeftMargin"
        android:background="@null"
        android:contentDescription="@string/button3View"
        android:src="@drawable/ic_settings_active" />
</RelativeLayout>

请帮助。

usrObj.authenticateUser()
为true时,您忘记调用
ButtonListener
方法。按如下方式操作:

if (usrObj.authenticateUser())
   {
        setContentView(R.layout.main_view);
        ButtonListener ();  << call here
   }
    else
        setContentView(R.layout.login);
if(usrObj.authenticateUser())
{
setContentView(右布局主视图);

ButtonListener();除了上述来自ρ∑ρѕρєK的建议之外,还有一件事需要注意

而不是下面的代码

oggleButton.setOnClickListener(new OnClickListener() {
用这个

oggleButton.setOnClickListener(new View.OnClickListener() { // use View.oncli......
oggleButton.setOnClickListener(new View.OnClickListener() { // use View.oncli......