[英]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.