First Solution:
You can call start activity inside your adapter like this:
public class YourAdapter extends Adapter {
private Context context;
public YourAdapter(Context context) {
this.context = context;
}
public View getView(...){
View v;
v.setOnClickListener(new OnClickListener() {
void onClick() {
context.startActivity(...);
}
});
}
}
Second Solution:
You can call onClickListener
of your button out of the YourAdapter
class. Follow these steps:
Craete an interface like this:
public YourInterface{
public void yourMethod(args...);
}
Then inside your adapter:
public YourAdapter extends BaseAdapter{
private YourInterface listener;
public YourAdapter (Context context, YourInterface listener){
this.listener = listener;
this.context = context;
}
public View getView(...){
View v;
v.setOnClickListener(new OnClickListener() {
void onClick() {
listener.yourMethod(args);
}
});
}
And where you initiate yourAdapter will be like this:
YourAdapter adapter = new YourAdapter(getContext(), (args) -> {
startActivity(...);
});
This link can be useful for you.