閱讀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 顯示隱藏文件和文件夾