在android中声明静态视图是个好主意吗? [英] Is it a good idea to declare static view in android?

查看:46
本文介绍了在android中声明静态视图是个好主意吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:我有一节课和一项活动:该类执行逻辑并使用复杂的算法从活动中操作 Textview 和 ImageView我在做什么:

The problem : I have one class and one activity: The class do the logic and use a complex algorithms that manipulate Textview and ImageView from the activity What I'm doing :

活动中:静态TextView txt1、txt2、txt3、txt4;所以我可以在课堂上使用:Activity.txt1

In activity : static TextView txt1, txt2, txt3, txt4; so I can use in the class : Activity.txt1

Android 编程有什么不好的地方吗?我想学习最佳实践.所以如果你有更好的方法,我会接受.谢谢

Is it something bad in Android programming ? I wanted to learn best practise. So if you have a better method I would take it. Thanks

推荐答案

我看不出你有什么理由想要这样做.静态变量在类的所有实例之间共享.但是视图与其特定的 Activity 实例密切相关,它们不能被多个实例使用——每个实例必须创建自己的实例.由 Activity 的一个实例创建的视图不能在第二个实例中显示.所以我看不到任何静态视图有好处的情况.

I can't see any reason you'd ever want to do that. Static variables are shared between all instances of a class. But views are very much bound to their particular instance of Activity, they cannot be used by multiple instances- each instance must create their own. A View created by one instance of an Activity cannot be displayed in a second instance. So I can't see any case where a static View is a benefit.

这篇关于在android中声明静态视图是个好主意吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆