gpt4 book ai didi

java - 无法在 Activity 中将小部件的值显示为 TextView

转载 作者:搜寻专家 更新时间:2023-11-01 09:33:10 26 4
gpt4 key购买 nike

github上有个项目https://github.com/codeka/advbatterygraph它在小部件中显示有关电池的不同属性,例如瞬时电流 (mA/h) 等。我下载了该项目,对其进行了编译,并在我的 Nexus 5 上运行它并且运行良好。

我想做的是从这个小部件中获取这个瞬时电流 (mA) 值,并使用 TextView 在 Activity 中显示它。

我研究了代码来解决问题,我发现:
1. 该值存储在 BatteryGraphWidgetProvider 中的 String(curr) 中类。
2. BatteryStatus 类有一个方法 getBatteryCurrentInstant();

我在我的 Activity 中尝试过这样的事情,但不够幸运:

BatteryStatus b = new BatteryStatus();
b.getBatteryCurrentInstant;

/*Made a TextView Variable, and by using "findViewById" method I got the
reference to that variable. Afterwards, I set it like this:*/

mMy_Variable.setText( (int) b.getBatteryCurrentInstant() );

结果:“很遗憾,App 停止工作了”。

如果这是新手问题太多,请原谅我,但我才刚刚开始 android 开发,我很确定每个人都经历过这个阶段。非常感谢任何关于如何完成此任务的帮助/想法/建议!

最佳答案

android TextView 对 setText 有多种实现。接受整数值的那个尝试从您的资源中检索字符串。 read more here .您应该将您的值作为 String 传递。你可以使用 Integer.toString(int)

关于java - 无法在 Activity 中将小部件的值显示为 TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45526978/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com