通过类之间的变量状态 [英] passing variable status between classes
问题描述
我正在一类布尔变量值,并访问该变量的状态在另一个类的布尔变量状态我的列表视图显示项目的基础上,
所以我的问题是
- 如何建立一个全球性的布尔varible
- 如何将它传递给另一个类
- 第二类是如何检查
让我提出3个选项。
你想通过Android活动之间的布尔变量?如果是这样,您可能需要使用捆绑。是的,那些小东西给活动的onCreate()
。你可以通过你自己的变量到这些,你的情况布尔值,与 putBoolean()
和 getBoolean()
你会使用Android的共享pref的?它是共享小preferences,如布尔标志,你的应用程序的部分之间并储存起来以备以后的界面。
或者,你可以只实施具有布尔变量和其他变量,你需要存储和您的应用程序内不同类型的检查单例类。
I am making a boolean variable value in one class and accessing the status of that variable in another class , on the basis of the boolean variable status my list view shows items,
So my question is
- how to create a global boolean varible
- how to pass it to another class
- how the second class check it
Let me suggest 3 options.
Do you want to pass a boolean variable between Android Activities? If so, You may want to use a Bundle. Yes, those little things given to Activities on onCreate()
. You can pass variables of your own into these, in your case a boolean, with putBoolean()
and getBoolean()
Would you prefer using Android's SharedPref? It's an interface for sharing small preferences, like boolean flags, between parts of your app and storing it for later.
Or, you could just implement a singleton class that has the boolean variable and other variables you need to store and check by different classes within your app.
这篇关于通过类之间的变量状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!