我想從活動發送數據到片段,但在我提交的片段數據中爲null。我不知道爲什麼。這是我發送數據並調用片段時的代碼。發送數據從活動到片段android studio
String b = "hahhaha";
Bundle bundle = new Bundle();
bundle.putString("coba" ,b);
bundle.putSerializable("modelassign" ,modelAssign);
// set Fragmentclass Arguments
ViewTaskFragment vtf = new ViewTaskFragment();
vtf.setArguments(bundle);
//call fragment
FragmentTransaction transact=getSupportFragmentManager().beginTransaction();
transact.add(R.id.content_frame, new ViewTaskFragment(), "viewtaskfragment");
transact.commit();
,這是代碼,當我檢索數據被髮送:
modelAssign = (ModelAssign) this.getArguments().getSerializable("modelassign");
String haha = this.getArguments().getString("coba");
誰能幫助?
WAW ..它是非常有幫助謝謝 –