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

  • Home
  • SEARCH
  • 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 7901653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:16:45+00:00 2026-06-03T09:16:45+00:00

in Android, I have list that I fill using the following code @Override public

  • 0

in Android,

I have list that I fill using the following code

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View rowView = inflater.inflate(R.layout.main, parent, false);
    TextView textView = (TextView) rowView.findViewById(R.id.label);
    ImageView imageView = (ImageView) rowView.findViewById(R.id.logo);
    textView.setText(values[position]);

    // Change icon based on name
    String s = values[position];

    System.out.println(s);

    if (s.equals("xxxxxxxx")) {
        imageView.setImageResource(R.drawable.one);
    } else if (s.equals("yyyyyyyyyy")) {
        imageView.setImageResource(R.drawable.two);
    } else if (s.equals("zzzzzzzzzzzzzzzzz")) {
        imageView.setImageResource(R.drawable.three);
    }

    // to change the background color


    return rowView;
}

how to change the selection color instead of orange , in the layout I use the following code

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:background="#DFE1E5">

    <ImageView
        android:id="@+id/logo"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="5dp"
        android:src="@drawable/one" >
    </ImageView>

    <TextView
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@+id/label"
        android:textSize="20dp" >
    </TextView>

</LinearLayout>

to solve that I did that

first add color xml to drwable

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

<resources> <color name="selection_color">#0587F4</color> 
</resources>

secondly I added XML to drwable to handle the selection

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

<selector  xmlns:android="http://schemas.android.com/apk/res/android">

    <item 
        android:drawable="@color/selection_color"

        android:state_selected="true"/>
   <!--  <item android:drawable="@drawable/list_selection_bg" android:state_pressed="true"/>
--> 
</selector>

the first problem is that it raaise error regardign “@color/selection_color”

any idea to achieve that

  • 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-03T09:16:47+00:00Added an answer on June 3, 2026 at 9:16 am

    Create a XML of Selector and save it in drawable folder

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@drawable/list_selection_bg" android:state_selected="true"/>
        <item android:drawable="@drawable/list_selection_bg" android:state_pressed="true"/>
    </selector>
    

    Then add the following code in getView method of the Adapter class

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    
        View rowView = inflater.inflate(R.layout.main, parent, false);
        TextView textView = (TextView) rowView.findViewById(R.id.label);
        ImageView imageView = (ImageView) rowView.findViewById(R.id.logo);
        textView.setText(values[position]);
    
        // Change icon based on name
        String s = values[position];
    
        System.out.println(s);
    
        if (s.equals("xxxxxxxxxxx")) {
        imageView.setImageResource(R.drawable.one);
        } else if (s.equals("yyyyyyyy")) {
        imageView.setImageResource(R.drawable.two);
        } else if (s.equals("zzzzzzzzzzzzzzzzz")) {
        imageView.setImageResource(R.drawable.three);
        }
    
        // to change the background color
    rowView.setBackgroundResource(R.drawable.alternate_list_color1);
    
    
        return rowView;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Android-support-v4 I have a PagerAdapter that displays a list fragment in each
I have created an ExpandableListView with the following code: <ExpandableListView android:id=@+id/android:list android:layout_width=wrap_content android:layout_height=0dp android:layout_marginTop=5dp
I have a list view that looks like this and that's its code ..
It seems that android has enforced that a listview must have the name android:id=@android:id/list,
I have an Android app with a ListActivity in the main view. The list
In my XML, I have the following <ListView android:id=@android:id/list android:layout_width=match_parent android:layout_height=fill_parent > </ListView> How
In my Android application, I have a simple list view with adapter. There's a
This one is weird. I have a list view that is a part of
I have List of items. I'm using custom adapter (Android 1.5). Everything works perfectly,
I have list view with custom row layout (list_row.xml) that contains CheckBox element: <TableLayout

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.