23
这里是我的代码不工作:发送捆绑与片段交易
//发送捆绑是这样的:
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");
基本上,数据未收到。我在正确的轨道上还是有更好的方法来做到这一点?
也做到了,谢谢。 – KickingLettuce 2013-03-11 00:17:28
只是为了澄清 - 调用getActivity()。getIntent()。getExtras()'实际上可以工作,但是你得到底层Activity的“参数”而不是'Fragment' :) – 2013-03-11 00:32:04
哦!得到它...再次感谢 – KickingLettuce 2013-03-11 01:03:06