I have implemented RecyclerView with some rows, and now I am trying to use AlertDialog to display a message when the user clicks on a row.
I successfully implemented setOnClickListener in the adapter, but I cannot get AlertDialog to work, the system keeps telling me that I cannot use AlertDialog.Builder in ViewHolder:
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
My github code is here
public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public TextView textView;
public ViewHolder(View itemView) {
super(itemView);
textView = (TextView) itemView;
itemView.setOnClickListener(this);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setTitle(null);
{
alertDialogBuilder
.setMessage("You selected ")
.setCancelable(true);
}
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
source
share