Fragment向dialog中传递集合(Activity向Fragment或Fragment向Activity类似)

本文详细介绍如何在Android开发中,使用Fragment与Dialog界面进行数据传递,并解析传递的JSON数据,将其转换为列表形式,进一步处理和展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

先定义一个集合,也可以用类对象

 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) {

                        }
                    }
                   
                }
            

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值