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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:19:34+00:00 2026-06-01T17:19:34+00:00

I am working with list view in android. I want to set background color

  • 0

I am working with list view in android.
I want to set background color for each item in list view.

If I use setbackgroudcolor function, it displays incorrect color. It seems there is the mix color of application background and new color.
If I use setbackgroundresource fund, it displays ok. However, when I click on an item, color is not change.

i need to set background for for each item on list view, and when click on an item, background is changed to other color or background

My code: OnView

    // Set background
    RelativeLayout root = (RelativeLayout) vi.findViewById(R.id.p60001_layout_info);
    if (position % 2 == 0){
        root.setBackgroundResource(R.drawable.cell_g_02);
        //root.setBackgroundColor(R.color.color_fist_in_pack_view);
    }else{
        root.setBackgroundResource(R.drawable.cell_g_01);
        //root.setBackgroundColor(R.color.color_fist_in_pack_view);
    }

Row layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/p60001_layout_info"
android:layout_width="match_parent"
android:layout_height="30dp">

<TextView
    android:id="@+id/p60001_item_info"
    android:layout_width="wrap_content"
    android:layout_height="30dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:textSize="15dp" android:layout_marginLeft="10dp" android:fadeScrollbars="false" android:textColor="@color/txt_normal" android:scrollHorizontally="true" android:gravity="center_vertical">
</TextView>

<ImageView
    android:id="@+id/icon"
    android:layout_width="22px"
    android:layout_height="30dp"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:src="@drawable/arrow" android:layout_marginRight="15dp"/>

<ImageView
    android:id="@+id/p60001_image_notice_num"
    android:layout_width="wrap_content"
    android:layout_height="25dp"
    android:layout_alignParentTop="true"
    android:layout_marginRight="30dp"
    android:layout_toLeftOf="@+id/icon"
    android:layout_marginTop="5dp" android:src="@drawable/fukidashi" android:visibility="invisible" android:clickable="false" android:focusable="false" android:focusableInTouchMode="false" android:longClickable="false"/>

<TextView
    android:id="@+id/p60001_item_notices"
    android:layout_width="10dp"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_toLeftOf="@+id/icon"
    android:ems="10" android:layout_marginRight="40dp" android:background="@android:color/transparent" android:freezesText="false" android:focusableInTouchMode="false" android:focusable="false" android:clickable="false" android:selectAllOnFocus="false" android:textSize="20px" android:layout_marginTop="4dp" android:visibility="invisible">

    <requestFocus />
</TextView>

</RelativeLayout>
  • 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-01T17:19:36+00:00Added an answer on June 1, 2026 at 5:19 pm

    If you are using custom adapter concept and the above is your getView code.

    you must a convert view(xml file of each row) change the background of it like below.

    if (position % 2 == 0){
        converterView.setBackgroundResource(R.drawable.cell_g_02);
        //root.setBackgroundColor(R.color.color_fist_in_pack_view);
    }else{
        converterView.setBackgroundResource(R.drawable.cell_g_01);
        //root.setBackgroundColor(R.color.color_fist_in_pack_view);
    }
    

    if you need to change the color on focus or pressed you use the below xml as background.

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

    also if need to set background for clicked items then a way to do this is::::

    to have a bool variable(=false)in your pojo(bean) where you are storing the data of each item.
    so when ever you click on item make that variable to true. And in getView() just check whether that variable is true or false and do the need full accordingly.

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

Sidebar

Related Questions

I am working on a custom list view. I want to show a CheckBox
I m working on android. i have made expandable list view and its working
I am working on a contact list project in android and i want to
i have implemented a list view its working fine but when i click on
I am working on an application, and from a list view I create a
So I'm working with a list view trying to get specific activities to open
I am working in android. I want to draw a comment window. in which
in my android app i am using expandable list view to display some text.These
I want to show an empty list view, which is then populated by user
So I have a ListView and I want to change the color of each

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.