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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:25:09+00:00 2026-06-03T18:25:09+00:00

Now I am using: android:listSelector=@drawable/bg_list_item android:drawSelectorOnTop=true where bg_list_item.xml: <?xml version=1.0 encoding=utf-8?> <item android:state_selected=true> <shape

  • 0

Now I am using:

android:listSelector="@drawable/bg_list_item"
android:drawSelectorOnTop="true"

where bg_list_item.xml:

<?xml version="1.0" encoding="utf-8"?>

<item android:state_selected="true">
    <shape android:shape="rectangle">
        <gradient android:startColor="#0000ff"/>
    </shape>
</item>

<item android:state_focused="false"
      android:state_pressed="false"
      android:state_selected="false">
    <shape android:shape="rectangle">
        <gradient android:startColor="#ff0000"/>
    </shape>
</item>

BUT first item is not working and selected item is not highlighting sometimes on scroll (when I am near top/bottom of my listview) and never on listView.setSelection(index).

Does I must to highlight current item programmaticaly?

  • 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-03T18:25:12+00:00Added an answer on June 3, 2026 at 6:25 pm

    define a custom adapter and in its getView() method:

    private int selectedItem;
    
    // is used outside the adapter for example OnItemClickListener
    public void setSelectedItem(int position) {
        selectedItem = position;
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
       //...
       // set selected item
        LinearLayout activeItem = (LinearLayout) rowView;
        if (position == selectedItem)
        {
           activeItem.setBackgroundResource(R.drawable.background_dark_blue);
        }
        else
        {
           activeItem.setBackgroundResource(R.drawable.border02);
        }
       //...
    }
    

    background_dark_blue.xml

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    
        <item>
    <shape android:shape="rectangle" >
    
                <solid android:color="@color/lightBlue6" />
                <!-- border width and color -->
    
                <stroke
                    android:width="2dp"
                    android:color="#FF0404B4" />
    
                <padding
                    android:bottom="2dp"
                    android:left="2dp"
                    android:right="2dp"
                    android:top="2dp" />
            </shape></item>
    
    </layer-list>
    

    border02.xml

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape android:shape="rectangle" android:layout_width="wrap_content">
                <stroke android:width="0.5dp" android:color="#FF000000" />
                <solid android:color="#FFFFFFFF" />
                <padding android:left="0dp" android:top="0dp" android:right="0dp"
                    android:bottom="0dp" />
                <corners android:radius="0dp" />
            </shape>
        </item>
    
    
    </layer-list>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i made news applicaion in android using RSS feed and now i want to
I'm building a little Android game using libgdx. For now I have a copy
Now i am doing an android application.In that application I am using asynchtask class
I'm using ormlite for my android-app. But now i have a problem. I have
I have been using Eclipse to compile and run my development Android app. Now
I am somewhat familiar to Java, but am using it more now for Android.
Right now I am using Android's Bundle to create requests for Facebook Query Language
I am using android 2.9 or something for my project. Now the project is
I am using android G1 phone and now I have upgraded my SDK to
I have created libffmpeg.so using the android build system. Now I'm trying to use

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.