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

  • Home
  • SEARCH
  • 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 5950017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:20:02+00:00 2026-05-22T17:20:02+00:00

I have a custom view for each row in a custom ListAdapter and I

  • 0

I have a custom view for each row in a custom ListAdapter and I am trying to perform onClick action and get the row position in the list where the click came from.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:paddingLeft="10dip" android:id="@+id/itemRoot" android:clickable="false">

    <TextView android:layout_width="wrap_content" android:text="TextView"
        android:layout_height="wrap_content" android:id="@+id/itemTxt"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"></TextView>
    <TextView android:layout_toRightOf="@+id/itemTxt" android:text="TextView"
        android:layout_height="wrap_content" android:layout_alignBottom="@+id/itemTxt"
        android:id="@+id/amountTxt" android:paddingLeft="6dip"
        android:layout_centerVertical="true" android:layout_width="match_parent"></TextView>
    <ImageView android:id="@+id/delBtn" android:layout_height="wrap_content"
        android:src="@drawable/delete" android:layout_width="wrap_content"
        android:layout_alignParentRight="true" android:paddingRight="10dip"
        android:layout_centerVertical="true"></ImageView>

</RelativeLayout>

I want to figure out when TextView or ImageView is clicked, I also need to know what row in the list it came form. I have tried using OnItemClickListener and it works fine to get the row where the click comes from. However, once I register an OnClick listener for the views, the onItemClicked() method gets skipped and onClick() is executed straight away, but there is no way of getting the row position that the view is in(or at least not that I know if).

If I set clickable to false for the views, then onItemClicked get called and I tried manually calling performClick() on the given view. But this only works for the root element (RelativeLayout), and if click comes from TextView inside the layout the click doesn’t propagate.

I can’t really figure out how to get both position in the list and perform onClick action.

Any thoughts are welcome.

Alex

  • 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-22T17:20:02+00:00Added an answer on May 22, 2026 at 5:20 pm

    You could assign the proper OnClickListener to each ImageView and TextView from inside your ListAdapter‘s overridden getView method.

    Inside that method you know the item’s position, so you can pass it to the custom listener classes, and use it there as you want:

    @Override
    public View getView(final int position, View convertView, ViewGroup parent)
    {
        // TODO: instantiate the layout 
        // here I call a super method
        final View view = super.getView(position, convertView, parent);
        final TextView textView = (TextView)view.findViewById(R.id.itemTxt);
        textView.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                Log.i("Click", "TextView clicked on row " + position);
            }
        });
        final ImageView imageView = (ImageView)view.findViewById(R.id.delBtn);
        imageView.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                Log.i("Click", "ImageView clicked on row " + position);
            }
        });
        return view;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a GridView in which each row has a custom view. The grid
I have a listview with 200 items. I use a custom view for each
I have a listview with custom rows and that extends SimpleAdapter. Each row consist
I have a custom control that is derived from ListView . This list view
I have used a custom array adapter to populate my list view.The problem i
I have made a custom listView which which extends ListActivity and each row contains
I have a custom view engine in ASP.NET MVC and since upgrading to RC1
I have question about NSView: Imagine a Custom View where the mouseDown, mouseDrag and
I have a view that I want to add some custom drawing to. I
I have a custom list adapter: class ResultsListAdapter extends ArrayAdapter<RecordItem> { in the overridden

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.