How to handle a click on the ListView item from the Activity in which it was created. Maybe this is a stupid question, but

 listview.setOnItemClickListener(new OnItemClickListener(){ public void onItemClick(AdapterView<?> parent,View view,int position,long id){ Toast toast = Toast.makeText(getActivity(),"gaaaaaaa", Toast.LENGTH_SHORT); toast.show(); } }); 

Does not help. If you call with a regular adapter, it works. But I have a custom one (by the way, if the handler is hung up on the item elements in getView, everything works. But I need to catch a click not in the adapter but in the Activity .

  • It looks all right. Please provide the code for the ListView located above this snippet. In what method do you have this code fragment? - Alexander Soloshenko

1 answer 1

You can implement View.OnClickListener in the activation, and then pass it to the adapter and in the getView method hang this listener (passed to the adapter) on the markup element you need. And you can pass position through setTag from View;