简体   繁体   English

如何将 textview 值从适配器 class 传递到另一个活动的 texview

[英]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.分两步进行。

  1. get the value from the adapter to the activity从适配器获取值到活动
  2. Then send the data from this activity to the other然后将此活动的数据发送到另一个

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正如您在代码中看到的那样,关键是likesl而在您的 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.

相关问题 如何将值从适配器传递到另一个 class - How to pass value from adapter to another class 如何将字符串从 textview 传递到同一活动的另一个 texview? - How do I pass the string from a textview to another texview on the same activity? 如何从SQLite数据库读取并将值传递给另一个类中的textview - How to read from a SQLite Database and pass the value to a textview in another Class 如何从Acivity类中在Recycler View Adapters上设置OnClick侦听器? 还是从第一个适配器访问其他RVAdapter? - How to set OnClick listener on Recycler View Adapters from within Acivity class? Or Access other RVAdapter from first Adapter? 如何在自定义对话框中将文本从xml文件中的TextView提取到TexView中? - How to fetch text from a TextView in xml file to a TexView in a custom dialog? 如何从适配器recycleview传递/获取值复选框到另一个活动 - How to pass/get value checkbox from adapter recycleview to another activity 如何将值从一个活动传递到另一个活动/适配器 - How to Pass a Value from One Activity to Another Activity/Adapter 如何在 android java 中保存另一个活动的背景颜色 - How to save background color from another acivity in android java 通过引用将ArrayList对象传递给另一个活动 - Pass ArrayList objects to another acivity by reference 如何将值从按钮传递到另一个类 - How to pass a value from a button to another class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM