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 3242732
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:20:59+00:00 2026-05-17T18:20:59+00:00

I have an Android app with a ListView, and each row in the list

  • 0

I have an Android app with a ListView, and each row in the list has a TextView and a Button. What I want to do is add an OnClickListener to each Button in the ListView, but I can’t figure out how to get some sort of reference to every Button… Can anyone please give me a hint?

Here’s my XML that’s bound to the ListAdapter:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView 
    android:id="@+id/row_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:textSize="18sp">
</TextView>
<Button
    android:id="@+id/row_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true" />
</RelativeLayout>

And I tried something like this, but it doesn’t work:

SimpleCursorAdapter rows = new SimpleCursorAdapter(this, R.layout.row_layout, cursor, from, to);
setListAdapter(rows);
Button button = (Button) getListAdapter().getView(0, null, getListAdapter()).findViewById(R.id.row_button);
button.setOnClickListener(new View.OnClickListener() {
    @Override public void onClick(View v) {
        Log.i(TAG, "clicked");
    }
}); 
  • 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-17T18:21:00+00:00Added an answer on May 17, 2026 at 6:21 pm

    It’s not possible using SimpleCursorAdapter… you will have to create your own adapter. If you don’t want to write a custom Adapter, at least try to enhance the SimpleCursorAdapter with new capabilities. For instance:

    public class YourAdapter extends SimpleCursorAdapter{
    
        public YourAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
            super(context, layout, c, from, to);
        }
    
        public View getView(int position, View convertView, ViewGroup parent){
            View view = super.getView(position, convertView, parent);
            Button button = (Button)view.findViewById(R.id.row_button);
            button.setOnClickListener(new View.OnClickListener() {
                @Override public void onClick(View v) {
                    Log.i(TAG, "clicked");
                }
            }); 
            return view;
        }
    }
    

    Then, you can do:

    SimpleCursorAdapter rows = new YourAdapter(this, R.layout.row_layout, cursor, from, to);
    setListAdapter(rows);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an android-app with a listview in an activity. The listview has, if
I have an Android app with a ListActivity in the main view. The list
In my android app I have a Tabhost with a ListView as one of
I'm doing some Android development, and I much prefer Visual Studio, but I'll have
I am currently working on my first android app. In a listview, I need
I'm creating my first android app (or attempting to anyway) and i have a
I have two threads in an Android application, one is the view thread, and
I'm quite new to Android development (started 2 days ago) and have been through
I am attempting to create a custom Adapter for my ListView since each item
Here's the problem. In my app, I have 5 tabs which contains activities. In

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.