[英]imageview and listview
我有一個帶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);
但在這種情況下,它將刪除列表中的所有圖像視圖
如何修復此錯誤,非常感謝
從列表中刪除元素后,請記住調用Adapter.notifyDataSetchanged()
以便ListView正確更新。
你有嘗試過嗎?
resolver.delete(DB_RDVUtils.CONTENT_URI, ligne,null);
ImageView icon = (ImageView) item.findViewById(R.id.icon);
icon. invalidateDrawable(icon.getDrawable());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.