is it possible to have method startActivtyForResult within an adapter?Then how to get the response? Where to execute the call back function?
I used a simpler method. create a public function in you activity/fragment which will call activity for result
public void startActivityFromAdapter(String Arguments){
//todo: add steps you would like to compute
startActivityForResult(Intent, REQ_CODE);
}
When creating the adapter, pass the current activity/fragment as an argument. I will use activity for example
public MyAdaper(Activity activity, ArrayList list){
this.activity = activity;
this.list = list;
}
call the public function from viewholder by casting the activity to the Activity Class
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.applyBt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
((ActivityName) activity).startActivityFromAdapter(list.get(position).code);
}
});
}
and use onActivityResult in your calling activity/fragment