When I came across this problem, I was not able to use Flags. I had to show a dialog for a clicked list item in a RecyclerView.
In the onclick method I created a variable for the dialog and then when building the dialog I enclosed it with an if statement that checks if the AlertDialog variable is null. When the user clicks on a list item the first time the dialog appears, because the variable is null, even if the user clicks on a item twice only one dialog will appear, because after the second click the AlertDialog variable is no longer null. When the user dismissed the AlertDialog the variable is set to null again.
AlertDialog alertDialog;
if(alertDialog == null) {
alertDialog = new AlertDialog.Builder(MyActivity.this)
.setTitle("Title for Dialog")
.setMessage("Dialog Message")
.setPositiveButton("Okay", null)
.setNegativeButton("No", null)
.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
alertDialog = null;
}
})
.show();
}