Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listview not clickable when the textview inside that listview is selectable

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view,
            int position, long id) {
        Log.d("test1","run");
    }
});

The listview is not fire , if I set like this:

    <TextView
        android:id="@+id/comment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/username"
        android:layout_below="@+id/username"
        android:autoLink="web"
        android:textIsSelectable="true"
        android:textColor="#000000"
        android:textSize="14dp" />

After I remove the textIsSelectable, the onitemclicklistener is fired.

I have studied a while, and I followed some suggestion on the internet

e.g.

put android:descendantFocusability="blocksDescendants" to parent view

The clicklistener is fired this time , but when select the text it show error:

TextView does not support text selection. Selection cancelled.

Can both function exist? thanks a lot

like image 316
user3538235 Avatar asked Jan 23 '16 04:01

user3538235


2 Answers

You can add manually OnClickListener to your parent in list adapter. Dont forget to delete android:descendantFocusability="blocksDescendants". I just tried it.

viewHolder.parent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(context, "Click", Toast.LENGTH_SHORT).show();
            }
        });
like image 72
Igori S Avatar answered Nov 19 '22 04:11

Igori S


Use below code,remove

android:textIsSelectable="true"

It may solve your problem.

viewHolder.textView.setOnClickListener
(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Toast.makeText(context, "Click", Toast.LENGTH_SHORT).show();
            }
        });
like image 24
UserAndroid Avatar answered Nov 19 '22 05:11

UserAndroid