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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:06:53+00:00 2026-05-22T18:06:53+00:00

I am using a custom expandable list adapter. I highlight a child when the

  • 0

I am using a custom expandable list adapter. I highlight a child when the user clicks on it. This works fine until the user opens/collapses a group. Say the user touches Group 2 Item 1. This highlights Group 2 Item 1. Then the user opens Group 1. Now Group 3 Item 2 is highlighted. I have done some testing choosing different items and I can not find a pattern where the highlighted row will jump to. Sometimes its up in the list, sometimes its down. I’m having trouble figuring out the logic to put in my activity’s onGroupExpandListener and onGroupCollapseListener to rehighlight the correct view. Any ideas?

EDIT: Current code inside my onChildClickListener

if (groupPosition == 0){ 
      switch(childPosition) {
      case 0: 
        previouslySelectedView.setBackgroundResource(R.color.transparent);
        currentlySelectedView.setBackgroundResource(R.color.blue); 
        break;

Same code for all the groups/children

  • 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-22T18:06:53+00:00Added an answer on May 22, 2026 at 6:06 pm

    Item slection in ExpandableListView is made through flat list (absolute positiond). Thus if the newlly opened group is before the currenet selection and has fewer children then the selection will move up and vice versa. I suggest to set choice mode to none and implement onclick/expand logic to handle focus on your own – implement tags for views, for example, and set the currently highlighted item via the tag.

    Here are few suggestions:

    1. In the ExpandableListView.OnChildClickListener first you perform ExpandableListView.findViewWithTag(theTag) to check for views with such tag and unmark them (also setTag(null)) and restore the background. Then for the item clicked setTag(theTag) and change the background to selected. Of course you can have some other logic and have multiple items marked. Note that once the view is destroyed you will lose the selection (for example during expands).
    2. Have some custom map or something that will hold a unique ID of the view and the (un)marked state. That’s the best solution that will allow to maintain persistent selection across scrolls and expands.
    3. In the backing adapter introduce a “marked” state. Thus the marking will be persistent even between application start/stop. Not a good approach, though, because selection is more of a UI behaviour.

    I am currently doing an ExpandableListView selection with Choice Mode Multiple of the list. But since, as I said, the selection is per position I had to sacrifice in terms of functionality – namely, I clear the selection whenever a manipulation is made. The previous implementation was with custom Map holding the selected IDs and – to honest – it was the better approach.

    This is how I get selected IDs (remember I use choice mode multiple):

    final SparseBooleanArray checkedPositions = expList.getCheckedItemPositions();
    final ExpandableListAdapter adapter = expList.getExpandableListAdapter();
    List<Long> checkedIds = new ArrayList<Long>();
    if (packedPositionType == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
        for (int i = checkedPositions.size() - 1; i >= 0; i--) {
            if (checkedPositions.valueAt(i)) {
                checkedIds.add(adapter.getGroupId(checkedPositions.keyAt(i)));
            }
        }
    }
    

    In your case, though, you will want to check for CHILD packed positions. Also note that my adapter has stable (unique) ids. If you do not have stable IDs then you can rely on ExpandableListView’s getPackedPositionForChild() method and store the packed position as marked.

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

Sidebar

Related Questions

I'm using custom renderer on JList, but none of components rendered are accessible. list.setCellRenderer(new
I am using custom model binder in ASP.NET MVC 2 that looks like this:
I am using Eclipse and created HelloWorld and it works fine using emulator. Then
I'm using custom SMTP servers and would like to verify the connection when user
When using custom classes with read-only properties that are of type List or similar
I am using custom permissions in my Django models like this: class T21Turma(models.Model): class
I have created a list using Custom List in Data Sheet View . After
I'm having a problem using custom components at runtime. I have this custom FlowLayoutPanel
Currently I am using custom made Java search engine. This Java engine uses Lucene
I've done this on android using custom layouts for menus. How do I create

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.