求解,listView里面嵌套listView数据显示混乱

我弄了个listView嵌套listView 从服务器上获取数据
最后显示出来,子项listView 把所有orderproduct里的数据都显示出来了,

Json格式大致是这样
{
    "code": "1",
    "result": [
        {
            "id": "10259",
            "createdate": "2014-06-30 21:23",
            "amount": "95.00",
            "score": "0",
            "paytype": "1",
            "statu": "已取消",
            "iscomment": "null",
            "orderproduct": {
                "picture": "/attached/image/20140120/1390185473547_3.jpg",
                "productid": "10308",
                "productname": "钢铁是怎样炼成的",
                "productnumber": "1",
                "productprice": "90.0"
            }
        },
        {
            "id": "10228",
            "createdate": "2014-03-04 17:50",
            "amount": "1085.00",
            "score": "0",
            "paytype": "1",
            "statu": "已取消",
            "iscomment": "null",
            "orderproduct": [
                {
                    "picture": "/attached/image/20140304/1393898360387_3.jpg",
                    "productid": "10262",
                    "productname": "儿童 新生婴儿纯棉防水围脖 围嘴 口水巾 宝宝超可爱绣花围兜围嘴",
                    "productnumber": "1",
                    "productprice": "12.0"
                },
                {
                    "picture": "/attached/image/20140304/1393898360387_3.jpg",
                    "productid": "10269",
                    "productname": "玛尚N6000 USB笔记本电脑有线鼠标 女生可爱鼠标有线 USB鼠标",
                    "productnumber": "1",
                    "productprice": "16.0"
                }
            ]
        }
    ]
}

当我单独读取订单号"id": "10228",这条数据时显示是正常的
下面的是Json解析的类
public static void orderListRead(String data, List<Info> list,
Context context) {
Info info;
OrderChildInfo childInfo;
OrderChildAdapter childAdapter;
List<OrderChildInfo> childList = new ArrayList<OrderChildInfo>();

try {
JSONObject jsonobject = new JSONObject(data);
JSONArray array = jsonobject.getJSONArray("result");
for (int i = 0; i < array.length(); i++) {
info = new Info();
JSONObject object = array.getJSONObject(i);
String id = object.optString("id");// 订单号
String time = object.optString("createdate");// 时间
String score = object.optString("score");// 积分
String status = object.optString("statu");// 状态
String amount = object.optString("amount");// 合计
JSONArray jsonArray = object.getJSONArray("orderproduct");
for (int j = 0; j < jsonArray.length(); j++) {
childInfo = new OrderChildInfo();
JSONObject objects = jsonArray.getJSONObject(j);
String name = objects.optString("productname");// 商品
String number = objects.optString("productnumber");// 数量
String price = objects.optString("productprice");// 价格
childInfo.setOrderChildName(name);
childInfo.setOrderChildCount(number);
childInfo.setOrderChildPrice(price);
childList.add(childInfo);
}
childAdapter = new OrderChildAdapter(context, childList);
info.setOderCode("订单号" + id);
info.setOderTime("时间:" + time);
info.setOderIntegral("积分" + score);
info.setOderPrice("合计" + amount);
info.setOderStatus(status);
info.setChildAdapter(childAdapter);
list.add(info);

}

} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

下面是adapter
public class OrderListAdapter extends BaseAdapter {
List<Info> list;
LayoutInflater inflater;
Context context;

public OrderListAdapter(Context context, List<Info> list) {
this.context = context;
this.list = list;
inflater = LayoutInflater.from(context);
}

@Override
public int getCount() {
// TODO Auto-generated method stub
return list == null ? 0 : list.size();
}

@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return list.get(arg0);
}

@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}

@Override
public View getView(int position, View view, ViewGroup arg2) {
// TODO Auto-generated method stub
OrderHolder holder;
if (view == null) {
holder = new OrderHolder();
view = inflater.inflate(R.layout.order_list_parent_item, null);
holder.orderCode = (TextView) view
.findViewById(R.id.order_item_code);
holder.orderStatus = (TextView) view
.findViewById(R.id.order_item_status);
holder.orderTime = (TextView) view
.findViewById(R.id.order_item_time);
holder.orderPrice = (TextView) view
.findViewById(R.id.order_item_price);
holder.orderIntegral = (TextView) view
.findViewById(R.id.order_item_integral);
holder.oderChildList = (ListView) view
.findViewById(R.id.order_item_list);
view.setTag(holder);
} else {
holder = (OrderHolder) view.getTag();
}
Info info = list.get(position);
holder.orderCode.setText(info.getOderCode());
holder.orderStatus.setText(info.getOderStatus());
holder.orderTime.setText(info.getOderTime());
holder.orderPrice.setText(info.getOderPrice());
holder.orderIntegral.setText(info.getOderIntegral());
holder.oderChildList.setAdapter(info.getChildAdapter());

return view;
}

class OrderHolder {
TextView orderCode = null;
TextView orderStatus = null;
TextView orderTime = null;
TextView orderPrice = null;
TextView orderIntegral = null;
ListView oderChildList = null;

}
下面是子项listView的adapter
public class OrderChildAdapter extends BaseAdapter {
List<OrderChildInfo> list;
LayoutInflater inflater;
Context context;

public OrderChildAdapter(Context context, List<OrderChildInfo> list) {
this.context = context;
this.list = list;
inflater = LayoutInflater.from(context);
}

@Override
public int getCount() {
// TODO Auto-generated method stub
return list == null ? 0 : list.size();
}

@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return list.get(arg0);
}

@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}

@Override
public View getView(int position, View view, ViewGroup arg2) {
// TODO Auto-generated method stub
OrderChildHolder holder;
if (view == null) {
holder = new OrderChildHolder();
view = inflater.inflate(R.layout.order_list_child_item, null);
holder.orderIcon = (ImageView) view
.findViewById(R.id.order_list_child_img);
holder.orderName = (TextView) view
.findViewById(R.id.order_list_child_name);
holder.orderCount = (TextView) view
.findViewById(R.id.order_list_child_count);
holder.orderPrice = (TextView) view
.findViewById(R.id.order_list_child_price);
view.setTag(holder);
} else {
holder = (OrderChildHolder) view.getTag();
}
OrderChildInfo info = list.get(position);
BitmapUtils bitmapUtils = new BitmapUtils(context);
bitmapUtils.display(holder.orderIcon, info.getOrderChildImg());
holder.orderName.setText(info.getOrderChildName());
holder.orderCount.setText(info.getOrderChildCount());
holder.orderPrice.setText(info.getOrderChildPrice());
return view;
}

class OrderChildHolder {
ImageView orderIcon = null;
TextView orderName = null;
TextView orderCount = null;
TextView orderPrice = null;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值