Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Listview shuffle image load from the net and local
    primarykey
    data
    text
    <p>I've a problem with a listview and shuffle image.</p> <p>Premise: I know that the cells/rows are re-used (recycled)</p> <p>My cell is made up of an image and some textview (to simplify we suppose, only one image and only one tetxview)</p> <p>if the image is present on the net (I know that by a bussines logic...) it's downloaded from the net (correct image); otherwise I put an image from application's bundle (default image)</p> <p>in this way, i've a shuffle images problem.</p> <p>Instead, if I load the defualt image always from the net, it's work fine.</p> <p>My question is: why? why if i load default-image from the net it's ok, but if i load default-image from the app's bundle I've shuffle images problem?</p> <p>Thanks in advance.</p> <p>Code of MyAdaper</p> <pre><code>public class MyArrayAdapter extends ArrayAdapter&lt;MyObject&gt; { final String URL_DEFAULT_IMG_USER="https://xxxxxxxxxxx/xxxx/default.png"; private LayoutInflater inflater; private List&lt;MyObject&gt; data; LinearLayout l1=null; Context context=null; public MyArrayAdapter(Context context,List&lt;MyObject&gt; objects) { super(context, R.layout.item_myobject, objects); inflater= LayoutInflater.from(context); this.data=objects; this.context=context; BitmapManagerNoCompressionUser.INSTANCE.setPlaceholder(BitmapFactory.decodeResource( context.getResources(), R.drawable.user)); } //ViewHolder class that hold over ListView Item static class ViewHolder{ //ImageView image; ImageView image; TextView displayName; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if(convertView == null){ convertView = inflater.inflate(R.layout.item_myobject, null); holder =new ViewHolder(); holder.image=(ImageView) convertView.findViewById(R.id.imageView); holder.displayName =(TextView) convertView.findViewById(R.id.textViewDisplayName); convertView.setTag(R.id.imageViewMyObject, holder.image); convertView.setTag(R.id.textViewDisplayName, holder.displayName); //set tag of convertView to the holder convertView.setTag(holder); } else { holder =(ViewHolder) convertView.getTag(); /* THIS CODE IS IRRELEVANT FOR THE SUFFLE PROBLEM, BUT I DONT'KNOW IF IT IS NECESSARY holder.image=(ImageView) convertView.getTag(R.id.imageViewMyObject); holder.displayName =(TextView) convertView.getTag(R.id.textViewDisplayName); */ } holder.image.setTag(position); // This line is important. if(data.get(position).getPathFotoServer()!=null ) { BitmapManagerNoCompressionUser.INSTANCE.loadBitmap(data.get(position).getPathFotoServer(), holder.image, 100,100); } else { BitmapManagerNoCompressionUser.INSTANCE.loadBitmap(URL_DEFAULT_IMG_USER, holder.image, 100,100); //IT'S OK //holder.image.setImageResource(R.drawable.default); //WITH THIS LINE, SHUFFLE IMAGE PROBLEM } holder.displayName.setText((CharSequence) data.get(position).getDisplayName()); return convertView; } } </code></pre> <p>Code of item_myobject</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout1" android:layout_width="match_parent" android:layout_height="60dp" android:orientation="horizontal" android:layout_gravity="fill_vertical" android:background="@drawable/state_item_listview" &gt; &lt;!-- android:layout_margin="5dp" --&gt; &lt;ImageView android:id="@+id/imageView" android:layout_width="60dp" android:layout_height="60dp" android:layout_margin="5dp" android:src="@drawable/user" /&gt; &lt;TextView android:id="@+id/textViewDisplayName" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Medium Text" android:gravity="left" android:textStyle="bold" android:textAppearance="?android:attr/textAppearanceMedium" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Update: add the code for sort items in the activity:</p> <pre><code>Collections.sort(data, new Comparator&lt;MyObject&gt;(){ public int compare(MyObject s1, MyObject s2) { Log.d(TAG, "s1.getDisplayName().compareToIgnoreCase(s2.getDisplayName():"+s1.getDisplayName()+" "+s2.getDisplayName()); return s1.getDisplayName().compareToIgnoreCase(s2.getDisplayName()); } }) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload