简体   繁体   English

recyclerView 的每个项目都对其自己的活动或片段开放

[英]every item of recyclerView open to its own activity or fragment

I have an recyclerView which contain items that i retrieve from database, now i want to click on the item, every item of recylerView go to unique activity by its id.我有一个 recyclerView,其中包含我从数据库中检索的项目,现在我想单击该项目,recylerView 的每个项目都通过其 ID 转到唯一的活动。

 itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(itemView.getContext(),detail_activity.class);
                itemView.getContext().startActivity(intent);

            }
        });

OnClickItem单击项

Intent intent=new Intent(itemView.getContext(),detail_activity.class);
intent.putExtra("id","ITEM_ID");
itemView.getContext().startActivity(intent);

In Activity class在活动类

String intentValue = getIntent().getStringExtra("id");

Do whatever you want by id.通过id做任何你想做的事。

As i recommend you to create a single Activity and pass the unique id or data from your adapter and set or get data according to this data because if recyclerView data come in large amount like 50 or 100 so its hard to create a new activity for each and every one.因为我建议您创建一个 Activity 并从您的适配器传递唯一的 id 或数据,并根据此数据设置或获取数据,因为如果 recyclerView 数据量很大,例如 50 或 100,则很难为每个创建一个新活动和每一个。 like pass the喜欢通过

Intent intent=new Intent(context,your_activity);
intent.putExtras("your_key",""+you_data);
context.startActivity(intent)

and get it into your second activity并将其纳入您的第二项活动

String intentValue = getIntent().getStringExtra("id");

and after this use this id to get the your items details并在此之后使用此 ID 获取您的商品详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 1 个 recyclerview 片段移动到它自己的活动? - How to move from 1 recyclerview fragment to its own activity? 如何根据RecyclerView中的单击项在新活动中打开特定片段 - How to open specific Fragment in new Activity depending on clicked item in RecyclerView 将Arraylist从片段传递到其自己的Activity - Pass Arraylist from fragment to its own Activity Java:如何为每个RecyclerView项目创建自己的总数计数器? - Java: How to make own total number counter for every RecyclerView item? 如何突出显示选定的 RecyclerView 项目并在 Activity 中使用其值 - How to highlight a selected RecyclerView item and use its values in Activity 将片段添加到RecyclerView中 - Add item to RecyclerView in Fragment 在Firebase RecyclerView Cardview中单击项目时如何打开详细信息活动 - How to open a details activity when an item is clicked in Firebase RecyclerView Cardview 当我单击 recyclerView 中的项目时打开特定活动 - Open an specific activity when I click an item from an recyclerView 由于 recyclerView 导致 Activity/fragment 滞后 - Lag in Activity/fragment due to recyclerView 引用位于Appcompat活动片段中的Recyclerview? - Reference a Recyclerview that was in a fragment in Appcompat activity?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM