Reputation: 1567
I have the Imageview inside the ListView. I tried to replace the image with code. But the new image is displaying over the old image. Two images are there in the imageview. How can I replace the old image which is already set in imageview with the new image I am getting from gallery inside the list.
xml:
<ImageView
android:id="@+id/imagelist"
android:layout_width="100dp"
android:layout_height="70dp"
android:background="@drawable/ic_launcher"/>
Inside ListView (code to set image in imageview)
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
Object[] imagelst=vehicle_imagePath.toArray();
Holder1 holder1=new Holder1();
View rowView1;
holder1.image.setImageResource(0);
holder1.image.setImageBitmap(BitmapFactory.decodeFile((String) imagelst[position]));
}
Upvotes: 0
Views: 136
Reputation: 795
Hi you can replace this line by
holder1.image.setBackground(BitmapFactory.decodeFile((String) imagelst[position]));
this one
holder1.image.setBackground(new BitmapDrawable(BitmapFactory.decodeFile((String) imagelst[position])));
or
This line in xml
android:background="@drawable/ic_launcher"
by this one..
android:src="@drawable/ic_launcher"
The basic reason is that you are setting image to background and in java code you are trying to replace it by its src (source). so it is not replacing your old image. you have to replace it by using either background or src.
Upvotes: 1
Reputation: 41
android:src tag should be used instead of android:background. src is the foreground image, and as the name says the other is the background.
Upvotes: 1
Reputation: 2826
it is because you are changing the source of the image and not the background. Do this:
<ImageView
android:id="@+id/imagelist"
android:layout_width="100dp"
android:layout_height="70dp"
android:src="@drawable/ic_launcher"/>
Upvotes: 1