Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6901099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:37:51+00:00 2026-05-27T07:37:51+00:00

This may not be the correct approach, if there is a better way pleas

  • 0

This may not be the correct approach, if there is a better way pleas tell me.
I’ve created a class of Custom Adapter & in my getView method I inflate the view I want to use

public View getView(int position, View convertView, ViewGroup parent) 
    {
        View v = mInflater.inflate(R.layout.wherelayout, null);
        if (convertView != null) 
        {
            v = convertView;
        }
        HashMap<String, Object> whereHash = (HashMap<String, Object>) this.getItem(position);
        if (whereHash != null) 
        {
            TextView whereId = (TextView) v.findViewById(R.id.tvWhere);
            TextView whereDetails = (TextView) v.findViewById(R.id.tvWhereDetails);
            ImageButton ibDelWhere = (ImageButton) v.findViewById(R.id.ibDelWhere);

            whereId.setText((CharSequence) whereHash.get("where"));
            whereDetails.setText((CharSequence) whereHash.get("details"));
            if (ibDelWhere != null)
            {
                ibDelWhere.setId(position);
                ibDelWhere.setOnClickListener(new OnClickListener() 
                  {

                    @Override
                    public void onClick(View v) 
                    {
                        //do stuff when clicked
                    }
                  }
                );
            }
        }
        return v;
    }

The view consists of 2 TextView aligned to the left & an ImageButton aligned to the right, I want to be able to delete the item from the ListView when the button is clicked. the layout is like this –

    <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="horizontal" android:clickable="true">
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:textSize="25sp" android:id="@+id/tvWhere" android:textColor="#00FF00" android:text="TextView" android:gravity="top|left" android:layout_alignParentTop="true" android:layout_alignParentLeft="true"></TextView>
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/tvWhereDetails" android:textColor="#0000FF" android:text="TextView" android:textSize="18sp" android:layout_below="@+id/tvWhere" android:gravity="bottom|left" android:layout_alignParentLeft="true"></TextView>
<ImageButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/eraser" android:id="@+id/ibDelWhere" android:layout_alignParentRight="true" android:layout_alignParentTop="true"></ImageButton>
</RelativeLayout>

The problem is that when the ImageButton is in the layout, I can click it & the onClick() fires as expected, but I can’t click the actual list item itself, i.e. click on the TextView items to fire the ListView.onItemClick that was assigned to it already. If I remove the ImageButton from the layout, then the ListView.onItemClick event fires when I click the item. Is there any way I can enable clicking both the ListView item & the button within the layout ?
Thanks guys & gals.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:37:52+00:00Added an answer on May 27, 2026 at 7:37 am

    You have to set the imagebutton as non focusable and non focusableInTouchMode (clickable is ok).

    Please note, as opposed as other views, you can’t do that in xml because the android:focusable gets overwritten in ImageButton‘s constructor.
    To be more precise, that’s one of the few differences between ImageView and ImageButton. See for yourself, this is the complete source of ImageButton.

    @RemoteView
    public class ImageButton extends ImageView {
        public ImageButton(Context context) {
            this(context, null);
        }
    
        public ImageButton(Context context, AttributeSet attrs) {
            this(context, attrs, com.android.internal.R.attr.imageButtonStyle);
        }
    
        public ImageButton(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
            setFocusable(true);
        }
    
        @Override
        protected boolean onSetAlpha(int alpha) {
            return false;
        }
    }
    

    To solve, just call setFocusable(false) from java. Or use an ImageView 🙂

    myImageButton.setFocusable(false);
    

    Hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may not be the correct way to use controllers, but I did notice
This may not be possible for the carousel but is there a way to
This may not really sound hard to do but it is currently killing me.
This may not be a programming question, but I don't know where to ask
This may not be the kind of question one should ask on StackOverflow, but
Sorry, this may or may not be a programming question directly, but I am
Okay, This may be really simple or it may not even be possible, or
Since LESS is a pre-compile stylesheet language, this may not achieve what I'm after,
This question may not directly relate to programming. I have noticed that the technology
This may seem a basic question but my is not currently working. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.