Fragment传递参数
来源:互联网 发布:阿里云域名认证步骤 编辑:程序博客网 时间:2024/05/01 01:15
转自:http://stackoverflow.com/questions/7149802/how-to-transfer-some-data-to-another-fragment
How to transfer some data to another Fragment?
up vote15down votefavorite
6
How to transfer some data to another Fragment
likewise it was done with extras
for intents
?
android
2 Answers
activeoldestvotes
up vote42down vote
Use a Bundle. Here's an example:
Fragment fragment = new Fragment();Bundle bundle = new Bundle();bundle.putInt(key, value);fragment.setArguments(bundle);
Bundle has put methods for lots of data types. Seehttp://developer.android.com/reference/android/os/Bundle.html
Then in your Fragment, retrieve the data (e.g. in onCreate()) with:
Bundle bundle = this.getArguments();int myInt = bundle.getInt(key, defaultValue);
getArguments is returning null – anirudhmaddy Apr 2 at 8:59
up vote3down vote
getArguments() is returning null because "Its doesn't get anything"
Try this code to handle this situation
if(getArguments()!=null){int myInt = getArguments().getInt(key, defaultValue);}
- Fragment传递参数
- 向Fragment传递参数
- Fragment之间传递参数
- Fragment传递参数
- Fragment参数传递(一)
- Fragment参数传递(二)
- fragment参数传递
- fragment传递参数
- fragment:传递参数
- fragment之间的参数传递
- Fragment之间参数的传递
- Activity传递参数到Fragment
- Fragment间参数的传递
- Activity向Fragment传递参数
- 两个Fragment之间参数的传递
- 两个Fragment之间参数的传递 .
- 两个Fragment之间参数的传递
- Fragment与Activity相互传递参数
- 遥感论文4
- hdu 4452 Running Rabbits (模拟—12年金华赛区现场赛K题)
- jquery的一张图片
- UIButton 长按消息的实现
- SQL学习笔记
- Fragment传递参数
- android可行代码小记
- 微信公众平台
- 【rmzt】蓝白世界win7主题
- Windows/MFC 如何区分鼠标双击和两次单击
- MyEclipse 8.5 安装SVN插件
- 正则表达式 /pattern/g中的g的含义
- contentprovider的学习实例总结
- source insight 用法 及快捷键