I have a custom adapter set for my ListView. I have also set the default item selection ripple animation to appear when an item is selected (android:background="?android:selectableItemBackground"
).
However, the animation won't appear when I tap the TextViews. Here's a video.
What I've tried, to no avail:
- setting the parent LinearLayout's descendantFocusability="blocksDescendants"
- adding clickable & focusable="false" to the TextViews
Here's my list_item.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:background="?android:selectableItemBackground"
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1" />
</LinearLayout>
(Edit) And in getView()
method in Adapter class I have these before return convertView
:
holder.title.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((ListView) parent).performItemClick(v, position, 0); // Let the event be handled in onItemClick()
}
});
holder.text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((ListView) parent).performItemClick(v, position, 0); // Let the event be handled in onItemClick()
}
});
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((ListView) parent).performItemClick(v, position, 0);
}
});
...to allow onItemClick
in MainActivity
(if I press the text or the linear layout, it opens up the same thing).