How to highlight ListView item on touch?
        Posted  
        
            by 
                AndroidNoob
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by AndroidNoob
        
        
        
        Published on 2011-03-09T15:43:29Z
        Indexed on 
            2011/03/09
            16:10 UTC
        
        
        Read the original article
        Hit count: 273
        
android
I have a simple ListView and I want each of it items to be highlighted on user's touch. I thought this should happen by default but it isn't. Can you advice?
ListView xml:
<ListView
    android:id="@+id/list_view"     
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:divider="#206600"
    android:dividerHeight="2dp"
    android:smoothScrollbar="true"
    android:background="#ffffff"
    >
</ListView>
And code of my Adapter:
private class MyAdapter extends ArrayAdapter<Task> {
        private LayoutInflater mInflater;
        public MyAdapter(Context context, int resource, List<Task> list) {
            super(context, resource, list);
            mInflater = LayoutInflater.from(context);
        }
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;
            if (v == null) {
                v = mInflater.inflate(R.layout.list_item, null);
            }
            Task task = taskList.get(position);
            /* Setup views from your layout using data in Object here */
            return v;
        }
© Stack Overflow or respective owner