0

を介してaHashMapを別のユーザーに渡そうとしています。しかし、私は戻ってきています。fragmentbundlebundlenull

これで を作成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)) {...

アプリケーションはクラッシュせず、エラーもありません。が never であるため、これfragmentは決して膨張しbundleません!= null。私は何を間違っていますか?

4

1 に答える 1

1

onPostExecute()FragmentTransaction を介してフラグメントを置換または追加する必要があります。

 Fragment newFragment = CountingFragment.newInstance(mStackLevel);
 FragmentTransaction ft = getFragmentManager().beginTransaction();
 ft.add(R.id.simple_fragment, fragment).commit();

また、infoList を繰り返し処理して、すべての HashMap を取得してバンドル内に配置することを避けることもできます。直接infoListを置くことができます

于 2013-06-07T19:37:08.593 に答える