I have a listview with a ImageView that appears when i click on one of the elements of the list.
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
ImageView icon = (ImageView) view.findViewById(R.id.icon);
icon.setImageResource(R.drawable.valider);
choiceDialog(view);
}
My layout file for the rows
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="1dip">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="6dip"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
<TextView
android:id="@+id/nom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
android:ellipsize="marquee"
android:textSize="15px"
android:textStyle="bold"
android:typeface="serif" />
/>
<TextView
android:id="@+id/date_heure"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
android:ellipsize="marquee"
android:textSize="15px"
android:textStyle="bold"
android:typeface="serif" />
<TextView
android:id="@+id/adresse"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="marquee"
android:textSize="15px"
android:textStyle="bold"
android:typeface="serif" />
</LinearLayout>
</LinearLayout>
The problem is that if I delete an element from the list, the ImageViewe is transferred to the element above whereas it was not clicked at first.
I tried to remove the image when the item is removed like this:
resolver.delete(DB_RDVUtils.CONTENT_URI, ligne,null);
ImageView icon = (ImageView) item.findViewById(R.id.icon);
icon.setImageResource(0);
but in this case, it removes all of the imagesview in the list
How to fix this bug please Thank you very much
从列表中删除元素后,请记住调用Adapter.notifyDataSetchanged()
以便ListView正确更新。
Have you tried this?
resolver.delete(DB_RDVUtils.CONTENT_URI, ligne,null);
ImageView icon = (ImageView) item.findViewById(R.id.icon);
icon. invalidateDrawable(icon.getDrawable());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.