fragment中怎么读取SharedPreferences数据

fragment中怎么读取SharedPreferences数据,第1张

fragment中怎么读取sharedpreferences数据

获取SharedPreferences的两种方式:

1 调用Context对象的getSharedPreferences()方法

2 调用Activity对象的getPreferences()方法

两种方式的区别:

调用Context对象的getSharedPreferences()方法获得的SharedPreferences对象可以被同一应用程序下的其他组件共享

调用Activity对象的getPreferences()方法获得的SharedPreferences对象只能在该Activity中使用

重写Fragment的onAttach()@Override public void onAttach(Activity activity) { // TODO Auto-generated method stub superonAttach(activity); //获取activity根视图,rootView设为全局变量 rootView=activitygetWindow()getDecorView(); }之后 把你上面的代码 RadioButton radioButton01 = (RadioButton)activityfindViewById(RidradioButton01);改为 RadioButton radioButton01 = (RadioButton)rootViewfindViewById(RidradioButton01);有些方法都忘得差不多了 查看更多答案>>

Fragment中如何获取listview我的FileFragment继承了Fragment,现在我想要在FileFragment中获取获取filexml

Fragment中如何获取listview

我的FileFragment继承了Fragment,现在我想要在FileFragment中获取获取filexml中的一个listview,我用了下面两种方式:

//fileListView=(ListView)getActivity()findViewById(Ridfile_list);得到空指针

fileListView=(ListView)inflaterinflate(Ridfile_list, null);找不到资源

请指教在Fragment中如何获取listview。

[解决办法]

View rootView = inflaterinflate(Rlayoutfile, null); //先解析filexml布局,得到一个view

ListView listView = (ListView) rootViewfindViewById(Ridfile_list);

以上就是关于fragment中怎么读取SharedPreferences数据全部的内容,包括:fragment中怎么读取SharedPreferences数据、Fragment 包在viewpager中怎么获取activity中的控件、怎么获取fragment中的view等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9462808.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-28
下一篇2023-04-28

发表评论

登录后才能评论

评论列表(0条)

    保存