I have gone across many demos on different CustomAdapter
but neither demo shows how we can actually get which activity we are using adapter for, inside the adapter. Right now I am using this approach for adapter
private Activity activity;
public CustomAdapter(Activity a, ArrayList d, Resources resLocal) {
activity = a;
....
}
At Activity a
I can actually get context but failed to get that on which activity I can use its function. While activity is still opened so there must be something to communicate to its functions. Anyway using following technique by me is totally reckless
try {
((HomeActivity) activity).onItemClick(mPosition); // function in other activity
}
catch (Exception e) {
((PlayActivity) activity).onItemClick(mPosition); // function in other activity
}
I am using same CustomAdapter
class for more than one activity so using try-catch to automatically find which method will not raise exception as I still do not know about the parent activity.
If anyway we can get to know about it that will be great!
Thanks for reading, Cheers!