Android:片段如何获取Activity的全局变量 [英] Android: how can fragment take a global variable of Activity

查看:1175
本文介绍了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的全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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