本文介绍了Android:片段如何获取Activity的全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有全局变量int x的活动,片段如何获得其活动的变量x的当前值?

I have an activity with a global variable int x, how can a fragment get the current value of variable x of its activity ?

推荐答案

将var设置为 public static ,或者使用

Either set the var as public static, or use

((MyActivity)getActivity()).getX()

这篇关于Android:片段如何获取Activity的全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 17:24
查看更多