I want to open my photos, set to a string representing the address (http). Create SimpleAdapter and his pass strings.
final ArrayList<HashMap<String,String>> CategoryList = UpdateMenuFromServer.getCategories();
final ListView ListCatalog = (ListView)findViewById(R.id.listView);
SimpleAdapter CatAdapter =new SimpleAdapter(this, CategoryList, R.layout.category_,
new String[] {"Name", "Image"},
new int[] {R.id.ProducerText, R.id.ProducerImage});
ListCatalog.setAdapter(CatAdapter);
R.id.ProducerImage
was treated Class CustomImageView
public class CustomImageView extends ImageView{
private static Context context;
public CustomImageView(Context context) {
super(context);
this.context = context;
}
public CustomImageView(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
}
public CustomImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.context = context;
}
public void setImageURI (Uri uri1){
try {
URL url = new URL(uri1.toString());
LoadImage load = new LoadImage(url);
load.execute();
} catch (IOException e) {
e.printStackTrace();
}
}
public class LoadImage extends AsyncTask<Void, Void, Drawable> {
private URL Url;
public LoadImage(URL url){
Url = url;
}
@Override
protected Drawable doInBackground(Void... voids) {
Drawable ShowImage = null;
try {
ShowImage = Drawable.createFromStream(Url.openStream(), null);
} catch (IOException e) {
//e.printStackTrace();
}
return ShowImage;
}
protected void onPostExecute(Drawable ShowImage) {
if(ShowImage!=null)
setImageDrawable(ShowImage.getCurrent());
}
}
}
ListView when loading the first element see it change all the pictures and only then load the other elements. My question is how can I avoid it and loading ListView to open my pictures already loaded.