The problem:
I have a ListView item with a relatively complex layout. One of the children in the list item view is a TextView with links. The TextView can handle the clicks on links found in it(by using Linkify), and has a OnClickListener that handles click on parts of the text that are not links. The listener will just get the position of the view in the ListView and perform a click:
@Override
public void onClick(View v) {
int position = mListView.getPositionForView(v);
mListView.performItemClick(v, position, mAdapter.getItemId(position));
}
Everything works fine, except the click doesn’t trigger the ListView to update the list item’s drawable state. It does trigger that when you click on other TextViews in the item that are not clickable.
Thanks!
Got it working.
Set the list item view
clickableand set its background as astate-listdrawable, also setaddStatesFromChildrentotrue. This will make sure the state of the list view item is changed when any of its children is clicked(assume the child is clickable).However, this will cause the
ListViewitself not receiving focus, so you need to handle the click by addingView.OnClickListenerto the list item itself instead of adding aOnItemClickedListenerto theListView.