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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:51:54+00:00 2026-05-30T00:51:54+00:00

I have two ListView in an XML, namely lvPrograms & lvEpisodes . They are

  • 0

I have two ListView in an XML, namely lvPrograms & lvEpisodes. They are placed horizontally.

I fill these ListViews from a web service.

When the Activity loads, i call the web service to get data for lvPrograms. when i receive Programs, i then load the Episodes for the first program in the retrieved list. and set the lvPrograms‘s first item as selected/highlighted, to show user that the loaded Episodes are for this Program item. I set it as follows:

private void highlightSelectedProgram(int _previousSelectedProgramIndex, int _currentSelectedProgramIndex) {
    ListView allProgramsList = (ListView) findViewById(R.id.allProgramsList);

    //Get the last selected List Item
    View selectedChild = allProgramsList
            .getChildAt(_currentSelectedProgramIndex);

    //_previousSelectedProgramIndex & _currentSelectedProgramIndex are to keep track 
    //of currently/previously selected PROGRAM index


    if (selectedChild != null) {

        // get selected shape
        Drawable shape = getResources().getDrawable(
                R.drawable.selected_item_selector);

        //change selected item background to be highlighted
        selectedChild.setBackgroundDrawable(shape);

        //change previous item, if any (is not -1), to normal state
        if (_previousSelectedProgramIndex != ._currentSelectedProgramIndex && _previousSelectedProgramIndex != -1) {
            TextView previousChild = (TextView) allProgramsList
                    .getChildAt(_previousSelectedProgramIndex);

            previousChild.setBackgroundResource(R.drawable.item_selector);
        }
    }       
}

I call this method when user clicks on PROGRAMS list item to highlight the item whose EPISODES are being loaded in lvEpisodes listview.

It looks like the following image.

enter image description here

Issues occur ONLY when the ListView has more items then its visible area. So when i click the first item, it background is changed by the above code BUT some other item , which is among the invisible items, also changes the background. WHY??

I think i have missed some thing OR handling the initially invisible list items is different.

OR You can guide me to a way where i can declare a background selector for that item which is CLICKED … and only the clicked item remain highlighted .. So if user clicks on some other item in the list which is among the hidden items, then that item becomes highlighted… so there must be a single HIGHLIGHTED item at any time in the list … This will be great If its possible.

any help is greatly appreciated as the release date is close.
Thanks

  • 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-30T00:51:56+00:00Added an answer on May 30, 2026 at 12:51 am

    use something like:

     lvPrograms.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
     lvPrograms.setSelector(R.drawable.programs_background);
    

    programs_background.xml

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
         <item android:state_activated="true"  android:drawable="@drawable/shape" />
    </selector>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Process objects that are monitored from two different views. A Windows.Forms.ListView (actually
I am creating a ListView . I have created two XML files, in the
I have a vertical linear layout with two ListViews. I want the top ListView
I have two problems with ListView+images. I get the values for the list from
I have two ItemsControls, one a ListView, and one a custom control I am
I have a listview with two columns and I'm using a context menu to
I have an Activity in Android, with two elements: EditText ListView When my Activity
I have a listview with several items that are created dynamically, each has two
I have a RelativeLayout with different elements. I was planning to have two ListViews
I have a page with two Listviews (with two different data sources). I have

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.