码迷,mamicode.com
首页 > 其他好文 > 详细

ListView中删掉某个item时出现整个ListView都看不见,但是数据源有改变

时间:2014-12-20 10:31:18      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:listview   删除   classcastexception   

搞了一个下午都没找到问题根源在哪里,醉了!!!可能是功夫不够吧!最近在弄一个listview的item删除,在每个item中加了删除按钮,删掉某行时,数据源有发生改变,但是ListView居然不见了,像是被隐藏了,怪咖。。。当时我的ListView布局是这样的:

<span style="font-size:14px;">  <ListView
        android:id="@+id/lv_collect_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="@null" /></span>

 

adapter里的布局是这样的:

<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rl_adapter_collect"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="5dp"
    android:orientation="vertical"
    android:padding="5dp" >

    <ImageView
        android:id="@+id/iv_collect_image"
        android:layout_width="90dp"
        android:layout_height="90dp"
        android:background="@drawable/default_image_185_140"
        android:contentDescription="@string/No"
        android:scaleType="fitXY" />

    <TextView
        android:id="@+id/tv_collect_desp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_toRightOf="@+id/iv_collect_image"
        android:ellipsize="end"
        android:lines="2"
        android:singleLine="false"
        android:text="eqeqeqeq大脚地哦啊大加大打击哦啊的骄傲就SADA懂啊激动啊dadadadada" />

    <TextView
        android:id="@+id/tv_collect_price2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/iv_collect_image"
        android:layout_marginLeft="8dp"
        android:layout_toRightOf="@+id/iv_collect_image"
        android:text="商城价:" />

    <TextView
        android:id="@+id/tv_collect_price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/tv_collect_price2"
        android:layout_alignBottom="@+id/tv_collect_price2"
        android:layout_toRightOf="@+id/tv_collect_price2"
        android:text="58.0"
        android:textColor="@color/red"
        android:textSize="16sp" />

    <View
        android:id="@+id/view1"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/iv_collect_image"
        android:layout_marginTop="5dp"
        android:background="@android:color/darker_gray" />

    <Button
        android:id="@+id/btn_collect_delete"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/view1"
        android:layout_alignParentRight="true"
        android:background="@drawable/red_change"
        android:padding="5dp"
        android:textColor="@android:color/white"
        android:text="删除" />

</RelativeLayout></span>

后来我该变了ListView的布局将
<span style="font-size:14px;"> android:layout_height="match_parent"</span>
改为
<span style="font-size:14px;"> android:layout_height="wrap_content"

</span>
结果是整个ListView点进去查看都已经报错了,跟上面的情况错误一样,”类转换异常“,技术分享

实在纠结,后面我再看了下adapter的View,重新改成如下:

<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="5dp"
    android:orientation="vertical"
    android:padding="5dp" >

    <RelativeLayout
        android:id="@+id/rl_adapter_collect"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/iv_collect_image"
            android:layout_width="90dp"
            android:layout_height="90dp"
            android:background="@drawable/default_image_185_140"
            android:contentDescription="@string/No"
            android:scaleType="fitXY" />

        <TextView
            android:id="@+id/tv_collect_desp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_toRightOf="@+id/iv_collect_image"
            android:ellipsize="end"
            android:lines="2"
            android:singleLine="false"
            android:text="eqeqeqeq大脚地哦啊大加大打击哦啊的骄傲就SADA懂啊激动啊dadadadada" />

        <TextView
            android:id="@+id/tv_collect_price2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/iv_collect_image"
            android:layout_marginLeft="8dp"
            android:layout_toRightOf="@+id/iv_collect_image"
            android:text="商城价:" />

        <TextView
            android:id="@+id/tv_collect_price"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/tv_collect_price2"
            android:layout_alignBottom="@+id/tv_collect_price2"
            android:layout_toRightOf="@+id/tv_collect_price2"
            android:text="58.0"
            android:textColor="@color/red"
            android:textSize="16sp" />

        <View
            android:id="@+id/view1"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/iv_collect_image"
            android:layout_marginTop="5dp"
            android:background="@android:color/darker_gray" />

        <Button
            android:id="@+id/btn_collect_delete"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/view1"
            android:layout_alignParentRight="true"
            android:background="@drawable/red_change"
            android:padding="5dp"
            android:text="删除"
            android:textColor="@android:color/white" />
    </RelativeLayout>

</LinearLayout></span>
终于可以了,但是我还是不太清楚原因,求大神指教!!!


ListView中删掉某个item时出现整个ListView都看不见,但是数据源有改变

标签:listview   删除   classcastexception   

原文地址:http://blog.csdn.net/u013807286/article/details/42040937

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!