2

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!

markmarch
  • 214
  • 3
  • 7

1 Answers1

2

Got it working.

Set the list item view clickable and set its background as a state-list drawable, also set addStatesFromChildren to true. 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 ListView itself not receiving focus, so you need to handle the click by adding View.OnClickListener to the list item itself instead of adding a OnItemClickedListener to the ListView.

markmarch
  • 214
  • 3
  • 7