Start new Activity with onClick() in RecyclerView

后端 未结 10 741
渐次进展
渐次进展 2020-12-03 06:12

I want to go into a new Activity with the onClick() method but my code is not working. Can you please offer some advice. I have some issues with the recyclerView, since it\'

10条回答
  •  时光取名叫无心
    2020-12-03 06:21

    I found the solution!:) There's this way of handling item click in Recyclerview with itemView given within the ViewHolder class:

     public static class ViewHolder extends RecyclerView.ViewHolder {
            public ViewHolder(LayoutInflater inflater, ViewGroup parent) {
                super(inflater.inflate(R.layout.fragment_channel, parent, false));
                itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Context context = v.getContext();
                        Intent intent = new Intent(context, ChannelDetailActivity.class);
                        context.startActivity(intent);
                    }
                });
            }
        }

提交回复
热议问题