【发布时间】:2018-11-16 23:20:08
【问题描述】:
我的应用有问题。
所以,我正在尝试将一些数据从 mainactivity 输入保存到另一个活动中。我想我发现了错误但无法修复它。
我相信我的应用主要在错误的活动中搜索 textview 引用。问题是我想更改另一个活动的文本视图。有没有人可以为我解释如何做到这一点或在这里给我一些建议?
public void saveEvent(View saveView){
Saved save=new Saved();
save.SaveNow(day,tvResultBefore.getText().toString(), tvResultAfter.getText().toString());
// 保存类
public class Saved extends MainActivity {
TextView tvMonthResult;
TextView tvResultBef;
TextView tvResultAft;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_save);
tvMonthResult=findViewById(R.id.tvMonthResult);
tvResultBef=findViewById(R.id.tvResultBef);
tvResultAft=findViewById(R.id.tvResultAft);
}
public void SaveNow(String day, String resBef, String resAft){
tvMonthResult.setText(month);
tvResultBef.setText(resBef);
tvResultAft.setText(resAft);
}
【问题讨论】:
-
错误是什么?
-
你能分享你整个涉及的代码以及错误吗?
-
您可以使用 Intent Extras 将数据从一个 Intent 传递到另一个 Intent。这是我认为最简单的方法。
标签: java android null textview