When an item is deleted in ListView, the entire ListView is invisible, but the data source is changed.
I couldn't find the root cause of the problem for one afternoon. I'm drunk !!! Maybe it's not enough effort! Recently, a listview item was deleted, and the delete button was added to each item. When a row was deleted, the data source changed, but the ListView disappeared, as if it was hidden, geeks... At that time, my ListView layout was as follows:
<ListView android:id="@+id/lv_collect_list" android:layout_width="match_parent" android:layout_height="match_parent" android:divider="@null" />
The layout in the adapter is as follows:
<? 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 ah dadadada"/> <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 = "mall price:"/> <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/custom" 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 = "delete"/> </RelativeLayout>
Later I should change the layout of the ListView
android:layout_height="match_parent"
Change
android:layout_height="wrap_content"
The result is that an error has been reported for viewing the entire ListView point. The error is the same as the preceding error. "Class conversion exception",
It's really tangled. Later I looked at the View of the adapter and changed it to the following:
<? 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 = "Product Name"/> <TextView android: id = "@ + id/TV _collect_price2" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: Layout = "@ + id/iv_collect_image" android: layout_marginLeft = "8dp" android: layout_toRightOf = "@ + id/iv_collect_image" android: text = "mall price:"/> <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/blank" android: layout_toRightOf = "@ + id/blank" 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 = "delete" android: textColor = "@ android: color/white"/> </RelativeLayout> </LinearLayout>
It's okay, but I still don't know why. Please advise me !!!