我有一个带有ImageView的列表视图,当我点击列表中的一个元素时会出现该视图。
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);
}
我的行布局文件
<?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>
问题是,如果我从列表中删除一个元素,ImageViewe将被转移到上面的元素,而它最初没有被点击。
我试图在删除项目时删除图像:
resolver.delete(DB_RDVUtils.CONTENT_URI, ligne,null);
ImageView icon = (ImageView) item.findViewById(R.id.icon);
icon.setImageResource(0);
但在这种情况下,它会删除列表中的所有图像视图
如何修复此错误 非常感谢你
答案 0 :(得分:0)
从列表中删除元素后,请记得调用Adapter.notifyDataSetchanged()
以便ListView正确更新。
答案 1 :(得分:0)
你试过这个吗?
resolver.delete(DB_RDVUtils.CONTENT_URI, ligne,null);
ImageView icon = (ImageView) item.findViewById(R.id.icon);
icon. invalidateDrawable(icon.getDrawable());