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
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();
}
});
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();
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With