[英]How to pass textview value from adapter class to texview of another acivity
I want to pass the value of textview from the adapter class to another textview of another activity.我想将 textview 的值从适配器 class 传递到另一个活动的另一个 textview。 please help me...
请帮我...
//recycleradapter class //回收适配器 class
Intent intent = new Intent(applicationContext, DetailActivity.class);
intent.putExtra("likes",holder.quantity.toString());
applicationContext.startActivity(intent);
// detail acivity class // 详细活动 class
String like = getIntent().getStringExtra("Likes");
Toast.makeText(this, like+"", Toast.LENGTH_SHORT).show();
item_quantiy.setText(like);
Do it in two steps.分两步进行。
Use an interface to trigger when the item in the recyclerview in clicked当recyclerview中的item被点击时使用一个接口来触发
In the interface implementation in the activity get that data and pass it to the next activity via an intent like you're doing here在活动的接口实现中获取该数据并通过意图将其传递给下一个活动,就像您在此处所做的那样
change改变
Intent intent = new Intent(applicationContext, DetailActivity.class);
intent.putExtra("likes",holder.quantity.toString());
applicationContext.startActivity(intent);
to到
Intent intent = new Intent(applicationContext, DetailActivity.class);
intent.putExtra("likes",holder.quantity.getText().toString());
applicationContext.startActivity(intent);
Check your key spelling.检查你的关键拼写。 as you can see in your code the key is
likes
with small l
and in your DetailActivity the key is Likes
with capital L
Change the code as below正如您在代码中看到的那样,关键是
likes
小l
而在您的 DetailActivity 中,关键是Likes
大写L
更改代码如下
Intent intent = new Intent(applicationContext, DetailActivity.class);
intent.putExtra("likes",holder.quantity.toString());
applicationContext.startActivity(intent);
to到
String like = getIntent().getStringExtra("likes");
Toast.makeText(this, like, Toast.LENGTH_SHORT).show();
item_quantiy.setText(like);
or you can create a class to store your keys like below或者您可以创建一个 class 来存储您的密钥,如下所示
public class SC{
private static final String KEY_LIKE = "likes"
}
then you can call this key in any class like SC.KEY_LIKE
然后你可以在任何 class 中调用这个键,比如
SC.KEY_LIKE
in adapter use context or activity for intent.(instead applicationContext)在适配器中使用上下文或活动的意图。(而不是 applicationContext)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.