当我单击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));
}
});
}
}