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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:36:18+00:00 2026-06-08T16:36:18+00:00

I am new to android and my an using list view, I want to

  • 0

I am new to android and my an using list view, I want to change list item color on selection but it is not working.

I have check almost all links on stack overflow and tried them all but no luck… Please check my code … and tell me where is the problem.

public class Main extends Activity {

    private ListView listView;
    private String[] menuArray;
    private List<String> menuList = new ArrayList<String>();
    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        menuArray = getResources().getStringArray(R.array.Menu);
        menuList = Arrays.asList(menuArray);

        listView = (ListView) findViewById(R.id.listView_main_menu);
        listView.setAdapter(new EfficientAdapter(this,menuList));       
    }

/******************************** EfficientAdapter ************************************/

    public class EfficientAdapter extends BaseAdapter{


        private LayoutInflater mInflater;
        @SuppressWarnings("unused")
        private String TAG=EfficientAdapter.class.getSimpleName();
        @SuppressWarnings("unused")
        private Context context;

        private List<String> data= new ArrayList<String>();

        public EfficientAdapter(Context context,List<String> data) {
            super();
            mInflater = LayoutInflater.from(context);
            this.context=context;
            this.data.addAll(data);
        }


        public EfficientAdapter(Context context) {
            super();
            mInflater = LayoutInflater.from(context);
            this.context=context;
        }
        public View getView(final int position, View convertView, final ViewGroup parent) {

            ViewHolder holder;

            if(convertView == null){
                convertView = mInflater.inflate(R.layout.main_list, null);              
                holder = new ViewHolder();
                holder.textLine = (TextView) convertView.findViewById(R.id.textView_mainlist_item);
                convertView.setTag(holder);
            }
            holder =(ViewHolder) convertView.getTag();
            holder.textLine.setText(getItem(position));

            convertView.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {

                }
            });

            return convertView;
        }

        public int getCount() {
            // TODO Auto-generated method stub
            return data.size();
        }

        public String getItem(int position) {
            // TODO Auto-generated method stub
            return data.get(position);
        }

        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return 0;
        }

        class ViewHolder {
            TextView textLine;
        }
    }
}

Here is my xml file with list view

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android1="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/Gainsboro"
    android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">


    <ListView
        android:id="@+id/listView_main_menu"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:cacheColorHint="#00000000"
        android:choiceMode="singleChoice"
        android:divider="@color/DarkGray"
        android:dividerHeight="1dip"
        android:fadingEdge="none"
        android:listSelector="@drawable/row_color"
        android:scrollbars="none" >

    </ListView>

</RelativeLayout>

row_color.xml

<item android:state_pressed="false" android:state_focused="false"
    android:drawable="@color/Green" />

<item android:state_focused="true"
    android:drawable="@color/Blue" />
<item android:state_pressed="true"
    android:drawable="@color/Brown" />

<item 
    android:state_selected="true" android:drawable="@color/Cyan" />

main_list.xml; this xml contain textview which is inflating

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">




    <TextView
        android:id="@+id/textView_mainlist_item"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="10dp"
        android:paddingLeft="20dp"
        android:paddingTop="10dp"
        android:text="TextView"
        android:textColor="@color/DarkSlateGray"
        android:textSize="20sp"
        android:textStyle="bold" />



    <TextView
        android:id="@+id/TextView01"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="right|center"
        android:paddingRight="30dp"
        android:paddingTop="6dp"
        android:text=">"
        android:textColor="@color/DarkSlateGray"
        android:textSize="28sp"
        android:textStyle="bold" />

</FrameLayout>

Just found that only this portion is working fine

<item android:state_pressed="false" android:state_focused="false"
        android:drawable="@color/Green" />
  • 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-08T16:36:20+00:00Added an answer on June 8, 2026 at 4:36 pm

    Visit http://android-codes-examples.blogspot.in/2011/03/customized-listview-items-selection.html

    Hope it works for you

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

Sidebar

Related Questions

i am creating a new android application.i am using the table layout. I have
I am new to Android development. In my project, I’m using EditText, but I
I'm using SeperatedListAdapter available here: http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android-09/ but I want to create a list with
In my Android application, I have a simple list view with adapter. There's a
I have an android activity that consists of a List View and a Text
in my android app i am using expandable list view to display some text.These
I want to have a list of elements (using a ListView) and each element
I want to display my arraylist results by using custom list view. for now
I want to save images in android using SharedPreference. I have two activity classes,
I'm new to Mono for Android (using MonoDevelop) and Android development in general. I

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.