如何从一个片段机器人访问活动变量 [英] How to access Activity Variables from a fragment Android
本文介绍了如何从一个片段机器人访问活动变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在活动,我有:
public class tabsmain extends Activity{
public static Context appContext;
public boolean lf_ch=false;
public void onCreate(Bundle savedInstanceState){
我想访问,并可能从一个片段里tabsmain改变lf_ch;
I would like to access and possibly change lf_ch from a fragment inside tabsmain;
public class tabquests extends Fragment{
public CheckBox lc;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)//onCreateView
{
lc.setChecked(//set it to lf_ch);
不过,我似乎无法访问lf_ch的价值。
However, I can't seem to access the value of lf_ch.
推荐答案
试试这个:
public View onCreateView(...){
tabsmain xxx = (tabsmain)getActivity();
lc.setChecked(xxx.lf_ch);
}
这篇关于如何从一个片段机器人访问活动变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文