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