I have a fragment with a listview in it.
The listview uses a custom adapter. Each item in the listview contains a button.
What I need is for the activity to know what button I press in the listview. I need this because the fragment needs too send a message to its activity depending on what button is pressed. So basically I want the OnClickListener to be in the fragment and not in the adapter.
I have tried to get the buttons from the list by itterating over all its elements and do a getChild(), but it does not react on click.
Button theButton = (Button)theListView.getChildAt(i).findViewById(R.id.button_id);
I have also tried with the getView on the adapter.
Button theButton = (Button) adapter.getView(i, null, null).findViewById(R.id.button_id);
Set the OnClickListener in the Adapter as usual but keep a reference to your fragment!
Let us say that your fragment class is MyFragment. Pass your fragment to the adapter; -i.e. in the constructor
In this way you can use
theFragmentin every OnClickListener you set.