pulltorefreshlistview 和xlistview 中的获取item控件布局时出现的类转换异常的问题:

本文详细介绍了如何避免在使用PullToRefreshListView和XListView时出现ClassCastException错误,特别是在处理头部和尾部布局时。通过正确地遍历子视图并跳过非列表项部分,确保了对子布局的正确类型转换。

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

pulltorefreshlistview 和xlistview 中的出现的类转换异常的问题在于
这两个listview都有头部和尾部在获取listview的子布局的时候应该这样:
//全选操作
public void selectAll(){
    System.out.println("gouwucheactivity中的count----"+listView.getChildCount());
    for (int index = 1; index < listView.getChildCount()-1; index++) {
        RelativeLayout layout = (RelativeLayout) listView.getChildAt(index);
        //            RelativeLayout layout = (RelativeLayout) ptr_listView.getChildAt(index);
        //            04-05 17:31:20.632: E/AndroidRuntime(28214): java.lang.ClassCastException: com.library.listview.XListViewHeader cannot be cast to android.widget.RelativeLayout

        CheckBox checkBox = (CheckBox) layout.findViewById(R.id.check_gouwu_select);
        //            CheckBox check_top = (CheckBox) layout.findViewById(R.id.check_gouwu_select1);
        checkBox.setChecked(true);
        //            check_top.setChecked(true);
        System.out.println("gouwucheactivity在购物车的selectAll方法中调用了");
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值