When adding an onClick listener to view inside the adapter, the ListView ListSelector does not work

I ran into this problem and it drives me crazy. I have the following adapter code:

private class ListAdaptor extends ArrayAdapter<String> {
        private ArrayList<String> listVO;

        public ListAdaptor(Context context, int textViewResourceId, ArrayList<String> items) {
            super(context, textViewResourceId, items);
            this.listVO = items;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;
            if (v == null) {
                v = ViewGroup.inflate(getContext(), R.layout.list_friends_inflate, null);
            }
            String o = listVO.get(position);
            TextView fullName = (TextView) v.findViewById(R.id.textViewName);
            fullName.setText(o);

            v.setOnClickListener(new OnClickListener() {                
                @Override
                public void onClick(View v) {
                    Toast.makeText(getApplicationContext(), "test", Toast.LENGTH_SHORT);
                }
            });
            /*v.setOnTouchListener(new OnTouchListener() {              
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    Toast.makeText(getApplicationContext(), "test2", Toast.LENGTH_SHORT);
                    return false;
                }
            });*/           
            return v;
        }
    }

This adapter class is inside ListActivity. When I click on the listView element, the listSelector style behavior does not occur. If I comment onClickListener and click it, it works. If I uncomment onTouchListener and touching the element, it also works, but I don't want the onTouch event, but onClick.

xml of the view that I will pump in the adapter:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp" android:clickable="false" android:focusableInTouchMode="false">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="65dp"
        android:layout_height="65dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" android:clickable="false" android:focusableInTouchMode="false"/>

    <TextView
        android:id="@+id/textViewName"
        style="@style/TextViewStyleCommon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView1"
        android:layout_marginBottom="18dp"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@+id/imageView1"
        android:textAppearance="?android:attr/textAppearanceMedium" android:clickable="false" android:focusableInTouchMode="false"/>

    <TextView
        android:id="@+id/textViewPoints"
        style="@style/TextViewStyleCommon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textViewName"
        android:layout_alignBottom="@+id/textViewName"
        android:layout_alignParentRight="true"
        android:layout_marginRight="10dp"
        android:textAppearance="?android:attr/textAppearanceMedium" android:clickable="false" android:focusableInTouchMode="false"/>

</RelativeLayout>

, , xml, , , onClick . , , ... .

styles.xml :

<style name="MyTheme" parent="android:Theme.Light">
        <item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowBackground">@drawable/ndp_background</item>
        <item name="android:windowFrame">@null</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:listViewStyle">@style/MyListView</item>
    </style>

    <style name="MyListView" parent="@android:style/Widget.ListView.White">
        <item name="android:listSelector">@drawable/list_subject_selector</item>
        <item name="android:cacheColorHint">@android:color/transparent</item>
    </style>

MyTheme Android...

- ? ,

+3
1

Listview, setOnItemClickListener.

list.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view,
        int position, long id) {
     Toast.makeText(getApplicationContext(), "test", Toast.LENGTH_SHORT);
    });
+1

All Articles