Since you assigned an OnClickListener
specific to that method, the int
parameter is the position in the list:
Parameters
dialog The dialog that received the click.
which The button that was clicked (e.g. BUTTON1) or the position of the item clicked
This means inside your method, you should be able to do this:
public static AlertDialog.Builder getAlertDialog(final String strArray[],
String strTitle, final Activity activity) {
AlertDialog.Builder alertDialogBuilder =
new AlertDialog.Builder(activity);
alertDialogBuilder.setTitle(strTitle);
alertDialogBuilder.setItems(strArray,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(activity, strArray [which], Toast.LENGTH_SHORT).show();
//rest of your implementation
}
});
return alertDialogBuilder;
}