通过类之间的变量状态 [英] passing variable status between classes

查看:178
本文介绍了通过类之间的变量状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一类布尔变量值,并访问该变量的状态在另一个类的布尔变量状态我的列表视图显示项目的基础上,

所以我的问题是


  1. 如何建立一个全球性的布尔varible

  2. 如何将它传递给另一个类

  3. 第二类是如何检查


解决方案

让我提出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

  1. how to create a global boolean varible
  2. how to pass it to another class
  3. 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屋!

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