我正在尝试将对象或 arrayList 从这个 fragment 传递到另一个 fragment 。我使用的是 Intent 方法,但遇到了同样的问题,我不知道应该在 bundle.putParcelable() 方法中放入什么参数。
BlankFragment1 sendData = new BlankFragment1();
final Series s = new Series(itemName.getText().toString(),
Integer.parseInt(itemYear.getText().toString())
,Integer.parseInt(itemNumberofSeas.getText().toString()),
dropDown.getSelectedItem().toString());
Bundle bundle = new Bundle();
bundle.putParcelable(s);
sendData.setArguments(bundle);
最佳答案
使用setArguments添加数据与putextra在activity中一样。
Bundle bundle = new Bundle();
bundle.putString("latitude", latitude);
bundles.putSerializable("KEY_ARRAYLIST", DIVID);
bundle.putString("longitude", longitude);
bundle.putString("board_id", board_id);
MapFragment mapFragment = new MapFragment();
mapFragment.setArguments(bundle);
获取数据使用getArguments,与Activity中的getExtra相同
String latitude = getArguments().getString("latitude")
Arraylist obj= getArguments().getSerializable("KEY_ARRAYLIST");
关于java - 使用 Android Studio 将对象或数组列表从一个 fragment 传递到另一个 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37186048/