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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:26:44+00:00 2026-05-25T13:26:44+00:00

I have an expandable list using a simplecursortreeadapter How would I integrate an onclicklistener

  • 0

I have an expandable list using a simplecursortreeadapter

How would I integrate an onclicklistener or any way to change the

Below is my script so far. I was trying to use the onclicklistener at the bottom of this post, but I cannot figure out how to change it from a listview to expandable listview listener for the children.

   protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.cattest);

            SQLiteDatabase checkDB = null;
            checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

            Cursor groupCursor = checkDB.rawQuery("SELECT * FROM countries", null);
            MySimpleCursorTreeAdapter mscta = new MySimpleCursorTreeAdapter(
                                                    this,
                                                    groupCursor,
                                                    R.layout.employee_list_item,
                                                    new String[] {"country"},
                                                    new int[] {R.id.country},
                                                    R.layout.employee_list_item,
                                                    new String[] {"employee"},
                                                    new int[] {R.id.lastName});
            setListAdapter(mscta);
            checkDB.close();


    }

    class MySimpleCursorTreeAdapter extends SimpleCursorTreeAdapter{

            public MySimpleCursorTreeAdapter(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);
            }


            @Override
            protected Cursor getChildrenCursor(Cursor groupCursor) {
                    String countryID = Integer.toString(groupCursor.getInt(0));
                    SQLiteDatabase checkDB = null;
                    checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

                    Cursor value = checkDB.rawQuery("SELECT * FROM employee WHERE _id='"+ countryID +"'", null);

                    String test = "";
                    if(value.moveToFirst())
                            test =  value.getInt(0) + ": " + value.getString(1);
                    while(value.moveToNext()){
                            test += ";" + value.getInt(0) + ": " + value.getString(1);
                    }
                    return value;
            }
    }

Tried implementing this

questionList = (ListView) findViewById (R.id.list);
sample(typedText);

questionList.setOnItemClickListener(
        new OnItemClickListener()
        {                   
            public void onItemClick(AdapterView<?> arg0, View view,
                    int position, long id) {
                Intent intent = new Intent(All.this, com.second.app.Second.class);
                Cursor cursor = (Cursor) adapter.getItem(position);
                intent.putExtra("EMPLOYEE_ID", cursor.getInt(cursor.getColumnIndex("_id")));
                //Cursor cursor = (Cursor) adapter.getItem(position);
                //intent.putExtra("EMPLOYEE_ID", cursor.getInt(cursor.getColumnIndex("_id")));
                startActivity(intent);
            }   
        }       
);

EDIT:

    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
            int childPosition, long id) {
        // use groupPosition and childPosition to locate the current item in the adapter

            Intent intent = new Intent(Categories.this, com.second.app.Second.class);
            Cursor cursor = (Cursor) mscta.getItem(childPosition);
            intent.putExtra("EMPLOYEE_ID", cursor.getInt(cursor.getColumnIndex("_id")));
            //Cursor cursor = (Cursor) adapter.getItem(position);
            //intent.putExtra("EMPLOYEE_ID", cursor.getInt(cursor.getColumnIndex("_id")));
            startActivity(intent);

        return true;
    }

At the moment the getChild(childPosition); is outputting the error

The method getItem(int) is undefined for the type
Categories.MySimpleCursorTreeAdapter

  • 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-25T13:26:45+00:00Added an answer on May 25, 2026 at 1:26 pm

    Look into the setOnChildClickListener method: http://developer.android.com/reference/android/widget/ExpandableListView.html#setOnChildClickListener(android.widget.ExpandableListView.OnChildClickListener)

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

Sidebar

Related Questions

I'm trying to make a list item expandable. Basically, I want to have a
I have an expandable list view I am using in one xml file which
Hi I have this expandable list, I'm getting an error when I'm trying to
I have seen in some places that while using Expandable List View we register
I have a set of divs that I want to make collapsible/expandable using jQuery's
I have an expandable list in android and I can fill it with string
I have a page with several expandable lists. In a perfect world, I would
I always have a problem trying to figure out the best way to make
I want to add an image icon in expandable list view .I have seen
Hi I have created Expandible list view using BaseExpandableListAdapter. If i scroll the list

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.