1. 程式人生 > >Fragment向dialog中傳遞集合(Activity向Fragment或Fragment向Activity類似)

Fragment向dialog中傳遞集合(Activity向Fragment或Fragment向Activity類似)

先定義一個集合,也可以用類物件

 List<String> strSize = new ArrayList<>();

然後在將要傳參的Fragment介面通過Bundle傳遞引數


String strResult = jsonObject.getString("result");//接收後臺傳過來的資料
strSize.add(strResult);//存入集合中
DialogJiaTingChengYuanRepeatContractInfoList dialogJiaTingChengYuanRepeatContractInfoList = new DialogJiaTingChengYuanRepeatContractInfoList();
Bundle bundle = new Bundle();
bundle.putSerializable("result", (Serializable) strSize);
bundle.putString("jiaTingHao", item.getJiaTingHao());
bundle.putString("PiLiangUpLoadDataActivity", str);
dialogJiaTingChengYuanRepeatContractInfoList.setArguments(bundle);
dialogJiaTingChengYuanRepeatContractInfoList.show(getFragmentManager(), "DialogJiaTingChengYuanRepeatContractInfoList");

在Dialog介面進行接收


List<String> hjtList = (List<String>) (getArguments().getSerializable("result"));
JSONArray jsonStr= new JSONArray(hjtList.toString());
for (int i = 0; i <jsonStr.length() ; i++) {
    JSONArray jsonData = jsonStr.getJSONArray(i);
    for (int j = 0; j < jsonData.length(); j++) {
        JSONObject jsonObject1 = jsonData.getJSONObject(j);
        if(jsonObject1.getInt("code")==1){
        JSONObject jsonObject2 = jsonObject1.getJSONObject("data");
        data.add(new JiaTingChengYuanRepeatContractInfoListItem(
        jsonObject2.getString("depId"),
        jsonObject2.getString("depName"),
        jsonObject2.getString("CJth"),
        jsonObject2.getString("VId"),
        jsonObject2.getString("VIdx"),
        jsonObject2.getString("CGrbh"),
        jsonObject2.getString("VJtlxr"),
        jsonObject2.getString("VXm"),
        jsonObject2.getString("VJtlxrx")
                  ));
                            
                             }else if (jsonObject1.getInt("code") == 0) {

                        }
                    }
                   
                }