public class RecyclerViewHolders extends RecyclerView.ViewHolder implements View.OnClickListener {
public TextView countryName;
public ImageView countryPhoto;
public RecyclerViewHolders(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
countryName = (TextView)itemView.findViewById(R.id.tv_cardTitle);
countryPhoto = (ImageView)itemView.findViewById(R.id.iv_cardImages);
}
@Override
public void onClick(View view) {
Toast.makeText(view.getContext(), "Clicked Country Position = " + getPosition(), Toast.LENGTH_SHORT).show();
}
}
答案 0 :(得分:0)
在RecyclerView的适配器类中的onCreateView()
方法中,您需要获取对您的卡或您想要点击的任何内容的引用,并且在附加您的卡时还需要传递Context
变量适配器RecyclerView
。
最后,在您的Activity中编写一个方法,如下所示:
public void openAnotherActivity() {
Intent intent = new Intent(this, NewActivity.class);
startActivity(intent);
}
在您的适配器中:
whateverItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
((Activity)context).openAnotherActivity();
}
});