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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:13:51+00:00 2026-06-01T03:13:51+00:00

I created an ExpandableListView with the help of this tutorial: link . I understand

  • 0

I created an ExpandableListView with the help of this tutorial: link.
I understand the code more or less and been trying to set a longclicklistener on the groups.

There is a setOnChildClickListener on the child items already and I managed to set a longclicklistener on them:

exList.setOnItemLongClickListener(new OnItemLongClickListener() {
      @Override
      public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
          if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
              groupPosition = ExpandableListView.getPackedPositionGroup(id);
              childPosition = ExpandableListView.getPackedPositionChild(id);
//[....]
 return false;
      }
  });  

How can I set a longclicklistener on the group items?

I know the code is hard to read so I created a sample project and uploaded it to here.
This has no onlongclicklistener on the childs, since this is almost the original from the above link.
I would appreciate if someone could help me with this.

  • 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-06-01T03:13:52+00:00Added an answer on June 1, 2026 at 3:13 am

    Group items are a subset of all items, so the method above should be called in either case. You’d then use getPackedPositionType as above to figure out if the selected item is a group, an item, or null.

    The code for this would be:

    exList.setOnItemLongClickListener(new OnItemLongClickListener() {
          @Override
          public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
              int itemType = ExpandableListView.getPackedPositionType(id);
    
              if ( itemType == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
                  childPosition = ExpandableListView.getPackedPositionChild(id);
                  groupPosition = ExpandableListView.getPackedPositionGroup(id);
    
                  //do your per-item callback here
                  return retVal; //true if we consumed the click, false if not
    
              } else if(itemType == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
                  groupPosition = ExpandableListView.getPackedPositionGroup(id);
                  //do your per-group callback here
                  return retVal; //true if we consumed the click, false if not
    
              } else {
                  // null item; we don't consume the click
                  return false;
              }
      });
    

    If it’s a group, you’ll use getPackedPositionGroup as above to get the group ID that is being long-pressed. If it’s an item, you’ll use the combination of getPackedPositionGroup and getPackedPositionChild.

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

Sidebar

Related Questions

I'm new to this ExpandableListView and I desperately need your help please. I'm using
I have created an ExpandableListView with the following code: <ExpandableListView android:id=@+id/android:list android:layout_width=wrap_content android:layout_height=0dp android:layout_marginTop=5dp
I created a single page (with code behind .vb) and created Public intFileID As
I am trying to create custom background selector for my ExpandableListView. It works fine
Created a UITextField for Postal Code/ZIP field with a keyboardType of UIKeyboardTypeDefault. I would
I need your help :) I have a EditText and below a ExpandableListView. I
I am trying to create an ExpandableListView with selectable elements(children) so that the selections
I created the register form in asp.net. And I want to validate Name. This
I have this code for an expandable list, I want to have a checkbox
Created a new App, created a new Fanpage for this App but if i

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.