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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:33:30+00:00 2026-06-17T18:33:30+00:00

i have a ListView on a ListFragment that use SimpleCursorAdapter to generate my list.

  • 0

i have a ListView on a ListFragment that use SimpleCursorAdapter to generate my list. i wanted to highlight selected item in my ListView, i’ve tried :

v.setBackgroundResource(R.color.listselect_light_blue);

in onListItemClick but it works odd and it selects two row when i click one of items and i want it to be single , i also set Choice Mode

<ListView android:id="@id/android:list"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent" 
           android:choiceMode="singleChoice"   
           android:cacheColorHint="#00000000"
            />

i’ve tried ListSelector but when i click on an item it doesn’t highlight until i scroll the list and it turn highlighted.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    getListView().setSelector(R.drawable.listview_selector);

}

and :

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="false" android:drawable="@color/listselect_light_blue" />
</selector>

any help would be appreciated

  • 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-17T18:33:31+00:00Added an answer on June 17, 2026 at 6:33 pm

    Try this way if you want to highlight selected item in Listview.

    This works for me.

    First set Adapter in Listfragment before use setSelector(..).

     setListAdapter(mAdapter);
     getListView().setSelector(R.drawable.fragment_listselector);      
    

    fragment_listselector.xml

    <selector xmlns:android="http://schemas.android.com/apk/res/android"
            android:exitFadeDuration="@android:integer/config_mediumAnimTime">
        <item android:state_activated="true"
                android:drawable="@drawable/list_item_active_pattern"  />
        <item  android:drawable="@drawable/list_bg_pattern" />
    </selector>
    

    when onItemClick(..) is called put this code.

        @Override
        public void onItemClick(AdapterView<?> parent, View v, int position, long id)
        {   
                getListView().setItemChecked(position, true);
                getListView().setSelection(position);
                getListView().setSelected(true);
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListFragment that populates a list using a SimpleCursorAdapter. It is using
I have a ListView in a ListFragment that is populated via a database query.
I have a ListFragment. In onCreateView I inflate a view that has a ListView
I have a ListFragment displaying a list of items that created by the user.
I have a ListView (technically its a ListFragment , but I dont think that
I have a ListView (part of a ListFragment ), and I noticed that when
I have a ListFragment containing a list of Earthquake objects that populates using a
I have a ListView in which every second item should have a different color
I have listview control.There is an option to remove selected items.After the user removes
I have ListView that has the following EditItemTemplate: <EditItemTemplate> <tr style=> <td> <asp:LinkButton ID=UpdateButton

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.