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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:42:57+00:00 2026-05-31T05:42:57+00:00

Here is what I’m working with: I have an ExpandableListView that uses a SimpleCursorTreeAdapter

  • 0

Here is what I’m working with: I have an ExpandableListView that uses a SimpleCursorTreeAdapter to fill the view from an SQLite Database. I’m using custom group and child views, and the group and child views both have buttons in them. I need to know how I can set a button listener on these buttons so that when the listener is called, I know what row (or cursor id) it came from. I am able to set a working listener onChildItemDetailsClicked(), but inside the listener I do not know which row corresponds to the button press. Any ideas?

public class MyListActivity extends ExpandableListActivity
{   
private DatabaseHelper mDbHelper;
private Cursor mGroupCursor;
private int mGroupIdColumnIndex;
private ExpandableListAdapter mAdapter;

/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);

        mDbHelper = new DatabaseHelper(this);
        mDbHelper.openDatabase();

        this.getExpandableListView().setItemsCanFocus(true);
        fillData();
    }

    private void fillData() 
    {
        mGroupCursor = mDbHelper.getAllGroupsCursor(); // fills cursor with list of top nodes - groups 
        startManagingCursor(mGroupCursor);

        // Cache the ID column index
        mGroupIdColumnIndex = mGroupCursor.getColumnIndex(DatabaseHelper.COL_ID);

        // Set up our adapter
        String[] groupCols = new String[] { DatabaseHelper.COL_TITLE, DatabaseHelper.COL_TEXT };
        int[] groupViews = new int[] { R.id.group_title, R.id.group_text };
        String[] childCols = new String[] {DatabaseHelper.COL_TEXT };
        int[] childViews = new int[] {R.id.child_text };

        mAdapter = new ExamineActivityAdapter(this, mGroupCursor, 
            R.layout.mylist_group_row, groupCols, groupViews,
            R.layout.mylise_child_row, childCols, childViews);

        setListAdapter(mAdapter);
}


    @Override
    public void onDestroy()
    {
        mDbHelper.close();
        super.onDestroy();
    }

    public class MyListActivityAdapter extends SimpleCursorTreeAdapter
    {   
        public MyListActivityAdapter(Context context, Cursor cursor, 
            int groupLayout, String[] groupFrom, int[] groupTo, 
            int childLayout, String[] childFrom, int[] childTo) 
        {
        super(context, cursor, groupLayout, groupFrom, groupTo, childLayout, childFrom, childTo);
        }

        // returns cursor with subitems for given group cursor
        @Override
        protected Cursor getChildrenCursor(Cursor groupCursor) 
        {
        Cursor childCursor = mDbHelper.getChildrenCursorForGroup(groupCursor.getInt(mGroupIdColumnIndex));
        startManagingCursor(childCursor);
            return childCursor;
        }
    }

    public void onChildItemDetailsClicked(View v)
    {       
        Toast toast = Toast.makeText(this, "child detail clicked.", Toast.LENGTH_SHORT);

        toast.show();
    }
}

Group View:

       <TextView
           android:id="@+id/group_title"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:gravity="center_vertical"
           android:textSize="20sp"
           android:singleLine="true"
       />

       <Button 
           android:id="@+id/group_detail_button"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:lines="1"
           android:textSize="12sp"
           android:text="@string/button_detail"
           android:focusable="false"
           android:layout_alignParentRight="true"
           android:layout_below="@id/group_title"
           android:layout_marginLeft="10dip" />

       <TextView
           android:id="@+id/group_text"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:ellipsize="marquee"
           android:textSize="12sp"
           android:lines="3"
           android:layout_toLeftOf="@id/group_detail_button"
           android:layout_alignTop="@id/group_detail_button"
       />

</RelativeLayout>

Child View:

    <TextView android:id="@+id/child_text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="2dip"
        android:gravity="center_vertical" />

    <Button android:id="@+id/child_detail_button"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:lines="1"
           android:textSize="12sp"
           android:text="@string/button_detail"
           android:focusable="false"
           android:onClick="onChildItemDetailsClicked"
           android:layout_alignParentRight="true"
           android:layout_below="@id/child_text"
           android:layout_marginLeft="10dip" />

    <CheckBox android:id="@+id/child_check"
        android:focusable="false"
        android:text="@string/yes"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/child_text"
        android:layout_toLeftOf="@id/child_detail_button"
        android:layout_alignTop="@id/child_detail_button" />

</RelativeLayout>
  • 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-31T05:42:58+00:00Added an answer on May 31, 2026 at 5:42 am

    Set ViewBinder to your adapter and there, add listener for buttons.
    this can help.

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

Sidebar

Related Questions

Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
Here is the problem that I am trying to solve. I have two folders
Here's a query that works fine: SELECT rowid as msg_rowid, a, b, c FROM
Here is my code (Say we have a single button on the page that
Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior
Here is the code from my project where I am using a datepicker. The
Here is my scenario. I have a website running under AppPool1 and that works
Here's the code I have. It works. The only problem is that the first
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }

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.