Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid ListView item selection issue
    text
    copied!<p>I have two ListView in an XML, namely <strong>lvPrograms</strong> &amp; <strong>lvEpisodes</strong>. They are placed horizontally. </p> <p>I fill these ListViews from a web service.</p> <p>When the Activity loads, i call the web service to get data for <strong>lvPrograms</strong>. when i receive <strong>Programs</strong>, i then load the <strong>Episodes</strong> for the first program in the retrieved list. and set the <strong>lvPrograms</strong>'s first item as selected/highlighted, to show user that the loaded <strong>Episodes</strong> are for this Program item. I set it as follows:</p> <pre><code>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 &amp; _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 &amp;&amp; _previousSelectedProgramIndex != -1) { TextView previousChild = (TextView) allProgramsList .getChildAt(_previousSelectedProgramIndex); previousChild.setBackgroundResource(R.drawable.item_selector); } } } </code></pre> <p>I call this method when user clicks on <strong>PROGRAMS</strong> list item to highlight the item whose <strong>EPISODES</strong> are being loaded in <strong>lvEpisodes</strong> listview.</p> <p>It looks like the following image.</p> <p><img src="https://i.stack.imgur.com/tVc8Z.png" alt="enter image description here"></p> <p>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??</p> <p>I think i have missed some thing OR handling the initially invisible list items is different.</p> <p><strong>OR</strong> 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.</p> <p>any help is greatly appreciated as the release date is close. Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload