I want to open dialog box when i click on ImageView in Recyclerview.
When i show Toast it's working(Showing) but when i want to show AlertDialog Box it's not working (on image click application crash) Please solve it. This is my Adapter Class:-
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.MyViewHolder> { private ArrayList<GetterSetter> arrayList; private Context context; public RecyclerAdapter(ArrayList<GetterSetter> arrayList, Context context){ this.arrayList = arrayList; this.context = context; } @NonNull @Override public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.detail,viewGroup,false); return new MyViewHolder(view); } @Override public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, final int i) { GetterSetter fp = arrayList.get(i); myViewHolder.nametxt.setText(fp.getEmpname()); myViewHolder.companytxt.setText(fp.getCompanyname()); myViewHolder.proImg.setImageResource(fp.getEmppic()); myViewHolder.callImg.setImageResource(fp.callpic); myViewHolder.msgimg.setImageResource(fp.msgpic); myViewHolder.callImg.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final Dialog dialog = new Dialog(context); dialog.setContentView(R.layout.design); dialog.setTitle("Dialog Box"); TextView text = (TextView) dialog.findViewById(R.id.text); text.setText("Android custom dialog example!"); Button button = (Button) dialog.findViewById(R.id.okbtn); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dialog.dismiss(); } }); dialog.show(); } }); } @Override public int getItemCount() { return arrayList.size(); } public class MyViewHolder extends RecyclerView.ViewHolder { ImageView proImg,callImg,msgimg; TextView nametxt,companytxt; public MyViewHolder(@NonNull View itemView) { super(itemView); itemView.setOnClickListener(null); proImg = itemView.findViewById(R.id.imageView); callImg = itemView.findViewById(R.id.smallimage1); msgimg = itemView.findViewById(R.id.smallimage2); nametxt = itemView.findViewById(R.id.name); companytxt = itemView.findViewById(R.id.company); } } }