我的代码如下
// 发送包
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();
// 接收包
Bundle extras = getActivity().getIntent().getExtras();
userName = extras.getString("userprofile");
但是数据没有接收。
需要用到fragment类中的getArguments()
方法。
举个例子:
Bundle extras = getArguments();
相关说明:
http://developer.android.com/reference/android/app/Fragment.html#getArguments()