简体   繁体   English

如何在 recyclerView 上打开两个不同的活动 - Kotlin

[英]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.我正在使用recyclerViewmainActivity中显示卡片电影列表,并且我已经实现了一个打开详细信息页面的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.

相关问题 如何在 Kotlin 中使用不同的条件/参数从 RecyclerView 的 Detail Activity 中打开一个新活动 - How to open a new activity inside the Detail Activity from RecyclerView with different conditions/parameters in Kotlin 如何在 RecyclerView kotlin 上的两个不同视图上实现两个 OnClickListener? - How to implement two OnClickListener on two different views on RecyclerView kotlin? 单击 Kotlin 中的任何 recyclerView 项目时如何打开不同的活动? - How to open different acitivies when click any recyclerView Items in Kotlin? 如何从片段内的特定选定项目 RecyclerView 导航到 Kotlin 中来自同一 RecyclerView 的 2 个不同的 Activity? - How to navigate from specific selected item RecyclerView Inside the Fragment, to 2 different Activity from same RecyclerView in Kotlin? 如何在 Android Kotlin 中打开具有不同数据的相同活动? - How to open same Activity with different data in Android Kotlin? 如何在 Kotlin 中打开 Recyclerview 的“详细信息”片段 - How to open a "Details" Fragment onclick of Recyclerview in Kotlin 如何从 kotlin 中的活动打开颤动视图? - How to open flutter view from an activity in kotlin? 如何从 Java Activity 打开 kotlin 片段? - How to open a kotlin fragment from java Activity? Kotlin RecyclerView 开始新活动 - Kotlin RecyclerView start new activity Kotlin 访问 recyclerView 适配器上的活动 - Kotlin access activity on recyclerView Adapter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM