java - 如何从一个活动中检索 int 数据并将其设置为另一个活动的 textView
问题描述
发送类代码:
Intent i = new Intent(this, QuizActivity.class);
i.putExtra("name", name);
startActivity(i);
接收类代码:
Intent intent = getIntent();
if (intent != null) {
totalScore = intent.getIntExtra("totalScore",0);
}
TextView scoreView = findViewById(R.id.totalScore);
scoreView.setText(totalScore);
解决方案
在发送方,使用 Intent.putExtra:
Intent myIntent = new Intent(A.this, B.class);
myIntent.putExtra("totalScore", intValue);
startActivity(myIntent);
在接收方,使用 Intent.getIntExtra:
Intent mIntent = getIntent();
int totalScore = mIntent.getIntExtra("totalScore", 0);
TextView scoreView = findViewById(R.id.totalScore);
scoreView.setText(totalScore+"");
推荐阅读
- java - 如何在 else/if 中忽略 args[1]
- sql - 基于多列postgresql的部分字符串匹配连接表
- python - 时间复杂度和算法加速
- java - java.sql.SQLSyntaxErrorException:指定的键太长,同时发生连接被拒绝
- javascript - 在型号 xxx 上找不到查询 xxx 的文档
- python - 用字符串和字符循环
- fastlane - Fastlane Match 无法验证证书和配置文件
- c++ - 可以将 c++ 运算符函数名称制作成模板吗?
- flask - sqlalchemy.exc.ArgumentError:SQLAlchemy - “POST”时出现Flask db错误?
- java - 如何动态创建文本字段和标签作为结果集中我的行数?