简体   繁体   English

imageview和listview

[英]imageview and listview

I have a listview with a ImageView that appears when i click on one of the elements of the list. 我有一个带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);
    }

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. 问题是,如果我从列表中删除一个元素,则ImageViewe会被转移到上面的元素,而最初并没有单击它。

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());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM