[英]How to open two different activity on recyclerView - Kotlin
I am using a recyclerView to show a list of card-movies in the mainActivity and I have implemented an onclickListener that open the details page.我正在使用recyclerView在mainActivity中显示卡片电影列表,并且我已经实现了一个打开详细信息页面的onclickListener 。
If I wanted one of the cards in the list to open a different activity, how can I set the click or, if necessary, the other elements I use?如果我想让列表中的一张卡片打开不同的活动,我该如何设置点击,或者,如果需要,我使用的其他元素?
on your onClick() method call the position of the card as follows在您的 onClick() 方法上调用卡的 position,如下所示
@Override public void onClick(View v) { @Override public void onClick(View v) {
final Intent intent;
switch (getAdapterPostion()){
case 0:
intent = new Intent(context, FirstActivity.class);
break;
case 1:
intent = new Intent(context, SecondActivity.class);
break;
...
default:
intent = new Intent(context, DefaultActivity.class);
break;
}
context.startActivity(intent);
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.