Stack Overflow archive
2 score

How to add custom click events to dynamic list view?

score
2
question views
102
license
CC BY-SA 3.0

I would like specific events to happen to each member of the listview when clicked

Set an AdapterView.OnItemClickListener on your ListView.

based on their content

Get the item at the current position and handle the event:

java
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

  @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Object item = parent.getAdapter().getItem(position);
    if ( /* your condition here */ ) {

    } else if ( /* something else */ ) {

    }
  }
});

Originally posted on Stack Overflow. Public user contributions are licensed under Creative Commons Attribution-ShareAlike.