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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:41:15+00:00 2026-06-02T16:41:15+00:00

I can’t change my listview item’s background color. protected void onCreate(Bundle savedInstanceState) { //

  • 0

I can’t change my listview item’s background color.

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.info_layout);
    ListView listView;
    listView = (ListView) findViewById(R.id.infolistView);
    final String[] values = new String[] { "TO1", "TO2", "TO3" };
    ArrayAdapter<String> adapter =
        new ArrayAdapter<String>(this,
                                 android.R.layout.simple_list_item_1,
                                 android.R.id.text1,
                                 values);
    listView.setAdapter(adapter);

    // This is not make anything , why ?
    View vi=adapter.getView(0, null, null);
    vi.setBackgroundColor(Color.YELLOW);

listView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
                //But here is running good
                view.setBackgroundColor(Color.RED);}
    });
  • 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-02T16:41:16+00:00Added an answer on June 2, 2026 at 4:41 pm

    You have to create Custom adapter to change the item’s Background Color.

    Here is the Example of Custom adapter:

    public class PaListAdapter  extends BaseAdapter{
            private LayoutInflater mInflater;
    
             private ArrayList<String> platevalue = new ArrayList<String>();
    
               ViewHolder holder;
            public PaListAdapter(Context context,ArrayList<String> value)
            {
                // Cache the LayoutInflate to avoid asking for a new one each time.
                mInflater = LayoutInflater.from(context);
    
    
    
                //mycontext = context;
                platevalue.clear();
                platevalue =value;
    
    
    
            }
    
    
            public int getCount() 
            {
                return platevalue.size();
            }
    
            public Object getItem(int position) 
            {
                return position;
            }
    
            public long getItemId(int position) 
            {
                return position;
            }
    
            public View getView(int position, View convertView, ViewGroup parent) 
            {
    
    
    
    
    
                if (convertView == null) 
                {
                     convertView = mInflater.inflate(R.layout.select_dialog, null);
    
                    holder = new ViewHolder();
                    holder.hTransID =(TextView) convertView.findViewById(R.id.txtChoice);
    
                    holder.ch   =(CheckBox) convertView.findViewById(R.id.chk);
    
    
                    convertView.setTag(holder);
                }
                else 
                {
                    holder = (ViewHolder) convertView.getTag();
                }
    
                holder.hTransID.setText(platevalue.get(position));
    
    
    
    
                return convertView;
            }
    
            static class ViewHolder 
            {      
                  TextView    hTransID;
    
    
            }
        }
    
    
    select_dialog.xml
    
    
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:descendantFocusability="blocksDescendants"
     android:background="#000000"
        >
    
        <TextView
            android:id="@+id/txtChoice"
    
            android:layout_gravity="center_vertical|left"
            android:gravity="center_vertical|left"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:textColor="#000000"/> 
    
    </LinearLayout>
    

    In Activity Class.Define it like:

       simpleefficientadapter efficientadapter;
    
       efficientadapter=new simpleefficientadapter(CLASSNAME.this, VALUES);
       listView.setAdapter(efficientadapter);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

can any one tell me how can change this java code into objective c.is
Can I open my custom developed form [instead of native one] when user opens
Can we set the alpha of drawable for its disable state through XML? For
Can anyone tell me how to hide the header in DevExpress gridcontrol..?? I'm using
Can the Application Name passed to SQL Server (via the ADO Connection string) be
Can we do following in SQL Server 2005 query with convert function. MaxRegID =
Can you set the internal [[Class]] property of an ECMAScript object?
Can multiple objects be linked (bound) to one name in RMI ? If that
Can someone please help me figure out why my accordion script at http://www.mincovlaw.com/services/copyright gets
Can't get Youtube's homepage, or any other youtube.com prefixed URL to load in an

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.