4

I'm using ImageButton in my xml, like this:

<FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        >
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageButton_home"
            android:src="@drawable/home_icon"
            android:background="@android:color/transparent"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="10dp"
            android:focusableInTouchMode="false"
            android:focusable="false"
            android:clickable="true"
            />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageButton_back"
            android:src="@drawable/back_icon"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="10dp"
            android:background="@android:color/transparent"
            android:visibility="gone"
            android:focusableInTouchMode="false"
            android:focusable="false"
            android:clickable="true"
            />

    </FrameLayout>

Only one image button is visible at a time. And I'm capturing the click in my java code as following:

  imageButtonHome.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent homeIntent = new Intent(SettingsActivity.this, MainActivity.class);
            startActivity(homeIntent);
        }
    });

This works fine sometimes, but not always. I see this line in my logcat whenever I click on image button:

D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN

This line always shows up, even when my ImageButton click action is not performed.

But when my ImageButton click works correctly, this other line adds up to log:

 D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
 D/AbsListView: Get MotionRecognitionManager

I want my image button to work every time. Please help.

pratiti-systematix
  • 792
  • 11
  • 28

4 Answers4

8

Give some padding to your ImageButtons in order to capture the touch event.

Febi M Felix
  • 2,799
  • 1
  • 10
  • 13
1

Use setOnClickListener(...) on the ImageButton

-1

Try to user LinearLayout instead of FrameLayout.

FrameLayout is thought for containing just 1 children.

Stefano
  • 3,127
  • 2
  • 27
  • 33
-2

Replace this and try.

imageButtonHome.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent homeIntent = new Intent(SettingsActivity.this, MainActivity.class);
        startActivity(homeIntent);
    }
});
Eranga Gamagedara
  • 536
  • 1
  • 3
  • 10