如何解决Android Studio:在另一个类中获取 Dialog TextView 的 id?
我正在尝试在 Activtiy A 的“remaining_amount_report”对话框中创建几个进度条:
public void setProgressBars(){
ProgressBar_Setup setup = new ProgressBar_Setup();
setup.createProgressBar(1,"product1",80);
setup.createProgressBar(2,"product2",60);
setup.createProgressBar(3,"product3",100);
setup.createProgressBar(4,"product4",20);
}
因此,我创建了一个“ProgressBar_Setup”类,其中方法是可访问的。 但问题是,由于我想覆盖Dialog的一些TextView Texts,所以我需要访问Class内部的Dialog。
该类扩展了活动 A,所以我通常应该像这样获得访问权限:
public void createProgressBar(int position,String productname,int progress) {
mposition = position;
switch(mposition){
case 1:
progressbar[0].setProductname(((TextView) remaining_amount_report.findViewById(R.id.remaining_amount_productname_1)));
但是我通过这样做得到一个空对象引用错误。
然后我尝试了一种不同的方法,通过向“createProgressBar”方法添加一个对话框变量(我猜这不是很好的行为):
public void setProgressBars(){
ProgressBar_Setup setup = new ProgressBar_Setup();
setup.createProgressBar(1,80,remaining_amount_report);
setup.createProgressBar(2,60,remaining_amount_report);
setup.createProgressBar(3,100,remaining_amount_report);
setup.createProgressBar(4,20,remaining_amount_report);
在 ProgressBar_Setup-Class 中
public void createProgressBar(int position,int progress,Dialog dialog) {
mposition = position;
switch(mposition){
case 1:
progressbar[0].setProductname(((TextView) dialog.findViewById(R.id.remaining_amount_productname_1)));
但还是一样的错误。
你能帮我吗?
谢谢!
解决方法
我认为您需要先使用 findViewById
来链接 progressbar
中的视图。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。