The*_*ter 23 android bundle android-fragments
这是我的代码不起作用:
//以这种方式发送包:
String topUser = String.valueOf(scores.get(arg2));
Bundle data = new Bundle();
data.putString("userprofile", topUser);
FragmentTransaction t = getActivity().getSupportFragmentManager()
.beginTransaction();
SherlockListFragment mFrag = new ProfileFragment();
mFrag.setArguments(data);
t.replace(R.id.main_frag, mFrag);
t.commit();
Run Code Online (Sandbox Code Playgroud)
//检索这种方式:
Bundle extras = getActivity().getIntent().getExtras();
userName = extras.getString("userprofile");
Run Code Online (Sandbox Code Playgroud)
基本上,没有收到数据.我是在正确的轨道上还是有更好的方法来做到这一点?
Tus*_*har 29
您应该使用getArguments()Fragment类的方法.所以在你的内容中添加以下内容Fragment:
Bundle extras = getArguments();
Run Code Online (Sandbox Code Playgroud)
参考:http://developer.android.com/reference/android/app/Fragment.html#getArguments()
| 归档时间: |
|
| 查看次数: |
20441 次 |
| 最近记录: |