I have a ListView and I populated it dinamically through an Adapter. Each row of my ListView have a button and I want to show a DialogBox when it is clicked. However I dunno how to pass the context to my AlertDialog, so it can show up on my activity. What I have is something like this:
....//ADAPTER
public View getView(int position, View view, ViewGroup parent) {
....
pay.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
AlertDialog.Builder ad = new AlertDialog.Builder();
ad.setMessage("Are you sure?");
ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog dialog = ad.create()();
dialog.show();
}
});
....
}
I guess I must add some kind of listener at the activity which extends my ListView but Im lost on how do it and the documentation is way too large, couldn’t find the solution.
You can pass an activity context to your adapter in a constructor and then use it in your adapter class: