阅读227 返回首页    go 阿里云 go 技术社区[云栖]


传递数据给Fragment的方法

原文:https://stackoverflow.com/questions/7149802/how-to-transfer-some-data-to-another-fragment

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. Seehttps://developer.android.com/reference/android/os/Bundle.html

Then in your Fragment, retrieve the data (e.g. in onCreate()) with:


Bundle bundle = this.getArguments();
if(bundle!=null){
    int myInt = getArguments().getInt(key, defaultValue);
}

最后更新:2017-04-03 18:52:09

  上一篇:go Android 线程池
  下一篇:go Ubuntu13.04 显示隐藏文件和文件夹