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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:10:11+00:00 2026-06-08T00:10:11+00:00

I have a listview that when I select an item, it populates a details

  • 0

I have a listview that when I select an item, it populates a details view. I want to show the item that was selected in the listview by changing it to green. Trouble is, the selected item does not show as green until I’ve clicked the same item two times. What am I doing wrong on
the selected item that keeps it from changing to green until the item is
clicked two times? Here is my xml selector file:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >

<!-- Active list item -->
<item android:state_selected="true"
    android:state_focused="false"
    android:state_pressed="false"
    android:drawable="@drawable/lv_bg_selected" />

<!-- Inactive list item -->
<item android:state_selected="false"
    android:state_focused="false"
    android:state_pressed="false"
    android:drawable="@drawable/lv_bg_unselected_state" />

<!-- Pressed list item --> 
<item android:state_pressed="true" 
    android:drawable="@drawable/lv_bg_pressed_state" />

</selector>

And onListitemClick:

@Override
public void onListItemClick(ListView l, View v, int position, long id)
{
 .
 .
 .
 v.setSelected(true);
 .
 .
 .
}
  • 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-08T00:10:13+00:00Added an answer on June 8, 2026 at 12:10 am

    Add the default state to the selector xml, specifically as the last item.

    <selector ...>
       ...
       ...
        <!-- Normal list item --> 
        <item android:drawable="@drawable/lv_bg_normal_state" />
    </selector>
    

    Update:

    Use the android:state_activated in your selector, setChoiceMode(ListView.CHOICE_MODE_SINGLE) on your listview and call setItemChecked() when an item is clicked.

    Inflate android.R.layout.simple_list_item_activated_1 in your getView method to get the CHOICE_MODE_SINGLE working.

    For more details, refer this post :
    Showing the current selection in a listview

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

Sidebar

Related Questions

I have a listview that you select a row/item on. This is linked to
I have a ListView. When I select an item in the ListView, I would
I have a listview with a textview as each item. I want to change
I have a listview and a button next to it that uses the selected
I have a ListView where each item is a TextView . I want to
I have a ListView that is a View and this all the properties will
I am trying to select an item in a listview and show the user
I have a query that selects rows in a ListView without having a limit.
I have ListView that has the following EditItemTemplate: <EditItemTemplate> <tr style=> <td> <asp:LinkButton ID=UpdateButton
I have ListView that uses a GridView to display several columns of data. Two

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.