我想在单击RecyclerView时打开对话框

时间:2018-08-18 19:02:21

标签: listview android-recyclerview dialog

当我单击RecyclerView时,我想打开对话框。

但是,如果我单击RecyclerView的视图,则该应用程序将关闭。

为什么会这样?

我正在观看//click event部分。我不能在这里修复它吗?或者如何解决?

class ViewHolder extends RecyclerView.ViewHolder{
    TextView aurthorText;

    public ViewHolder(View itemView) {
        super(itemView);
        aurthorText = itemView.findViewById(R.id.aurthorText);
    }
}

public class RecyclerAdapter extends RecyclerView.Adapter<ViewHolder> {

    private Context context;
    private int resourceId;
    private List<RecyclerModel> dataList;

    public RecyclerAdapter(Context context, int resourceId, List<RecyclerModel>dataList){
        this.context=context;
        this.resourceId=resourceId;
        this.dataList=dataList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(resourceId,parent,false));
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        RecyclerModel recyclerModel = dataList.get(position);
        holder.aurthorText.setText(recyclerModel.getAurthor());
//        Toast.makeText(context, "click checking", Toast.LENGTH_SHORT).show();
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // click event
                context.startActivity(new Intent(context, Plzfinish.class));
            }
        });
    }
}

0 个答案:

没有答案