I'm new to android, I work on an app. I want to download an image and show it in list item. I used many functions for that. My code runs without error but image doesn't display on screen that's part of my code.
public loader(Context context, String[] img) {
super(context, R.layout.item, img);
this.context = context;
this.img = img;
inflater = LayoutInflater.from(context);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// ImageView imgshow = (ImageView) findViewById(R.id.image1);
if (null == convertView) {
convertView = inflater.inflate(R.layout.item, parent, false);
}
ImageView imageView = (ImageView) convertView.findViewById(R.id.imageview);
//first method
// Glide.with(context)
// .load(img[position])
//.into(imageView);
//second method
DownloadImageTask download=new DownloadImageTask((ImageView) convertView.findViewById(R.id.imageview));
download.execute("http://previews.123rf.com/images/faysalfarhan/faysalfarhan1402/faysalfarhan140200008/25989999-Back-left-arrow-icon-glossy-purple-button-Stock-Photo.jpg");
//new DownloadImageTask((ImageView) convertView.findViewById(R.id.imageview))
//.execute(img[position]);
//third method
//Picasso.with(context).load(img[position]).into(imageView);
//Log.e("image_url","https://upload.wikimedia.org/wikipedia/commons/thumb/2/27/Square_200x200.svg/1024px-Square_200x200.svg.png");
return convertView;
}
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
TextView t;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = "http://previews.123rf.com/images/faysalfarhan/faysalfarhan1402/faysalfarhan140200008/25989999-Back-left-arrow-icon-glossy-purple-button-Stock-Photo.jpg";
Bitmap mIcon11 = null;
// Toast.makeText(mainpage.this ,urldisplay ,Toast.LENGTH_SHORT).show();
TextView t=(TextView)findViewById(R.id.texttt);
// t.setText(urldisplay);
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
}
I put that in my list using (img is array of strings I save urls in it and display them but for testing I replace it by one image url inside loader class)
String[] img = new String[1000];
loader im=new loader(mainpage.this,img);
lv.setAdapter(im);