I have a gallery with a custom adapter. I’m showing an image along with some texts and buttons.
I want to change the texts that are associated with the images when the corresponding buttons are clicked.
If I put the button handler inside the adapter, it doesn’t catch the call.
I found out that I should moved the handler to the activity.
But the problem is that I don’t have access to the Adapter anymore. Any solutions?
public class MyAdapter extends BaseAdapter { ...
MyGallery myGallery = (MyGallery) findViewById(R.id.mygallery);
myGallery.setAdapter(new MyAdapter(this, ...));
You should set the OnClickListener in the getView function of the adapter. When you inflate the view you can make a call to findViewById on the view to get a reference to the Button. You can then set the OnClickListener on the Button object itself.