Custom Alert Dialog With RecyclerView

前端 未结 6 910
轮回少年
轮回少年 2020-12-19 02:24

I\'m using RecyclerView to list some text and now I want to make it so that when the user clicks on text a custom Alert Dialog box pops up.

I have tried

6条回答
  •  粉色の甜心
    2020-12-19 02:41

    You are using context which is null so pass the context in ViewHolder constructor and in CBAdapter constructor also like as below:

    public class CBAdapter extends RecyclerView.Adapter {
    
    List mItems;
    Context context;
    
    public CBAdapter(Context context) {
        super();
        this.context = context;
        .....
      }
    

    And in ViewHolder class

    class ViewHolder extends RecyclerView.ViewHolder{
    
        public TextView textOne;
        private Context mcontext;
    
    
        public ViewHolder(View itemView, Context mcontext) {
            super(itemView);
            this.mcontext = mcontext;
            ....
       }
    

提交回复
热议问题