我正在尝试将 a 传递HashMap
给另一个fragment
via bundle
。不过我bundle
的回来了null
。
我bundle
用这个创建
protected void onPostExecute(String string) {
// dismiss the dialog
pDialog.dismiss();
int a = 0;
Bundle bundle = new Bundle();
Fragment fragment = new Assessment_Fragment();
for (int i = 0; i < infoList.size(); i++) {
// get HashMap
HashMap<String, String> map = infoList.get(i);
// autoincremented key for retreiving as many HashMaps as needed
bundle.putSerializable("" + a, map);
// so i will know how many hashmaps exist
bundle.putInt("key", a);
// increment key
a++;
}
fragment.setArguments(bundle);
};
这就是我收到的方式bundle
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_assessment, container, false);
// check for values
if (getArguments() != null) {
// application never gets here !
int a = getArguments().getInt("key");
for (int i = 0; i < a; i++) {
@SuppressWarnings("unchecked")
HashMap<String, String> map = (HashMap<String, String>) getArguments()
.getSerializable("" + i);
if (map.get(TAG_FIELD).equals(r)) {...
应用程序没有崩溃,没有错误。这fragment
根本不会膨胀,因为bundle
is never != null
。我究竟做错了什么?