The workaround I found avoids
AdapterView.OnItemClickListener mMessageClickedHandler=new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { } };
in a ListView , but use the Adapter constructor, which takes a Context as parameter:
myCustomAdapter=new MyCustomAdapter(ActivityName.this,...)
Passing ActivityName.this allows you to use Context in the adapter class as ActivityName safe way and use its methods that work as callbacks:
((ActivityName)context).activityMethod()
Given that the getView() method of the Adapter class has a position parameter, you can pass this value to activityMethod(int position) to find out which list item was clicked in the Activity, where the ListView is.
Mattia Personaggio Uno Ducci
source share