1
我需要將我的FragmentActivity中的對象傳遞給我的片段。我有這段代碼試圖從FragmentActivity傳遞一個字符串,但是當我嘗試進入Fragment時,我得到了NullPointerException。無法將對象或字符串從FragmentActivity傳遞到片段
Bundle bundle = new Bundle();
Descripcion f2= new Descripcion();
bundle.putString("lugar", lugar.getDescripcionLugar());
//bundle.putSerializable("lugar", lugar);
f2.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.principal, f2).commit();
片段中的我......
private String des;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
des=getArguments().getString("lugar"); // Here I get NullPointerException
}
我如何傳遞一個字符串或對象?
謝謝。