I have a String[] with contains ten image url sources, and I'm trying to get ImageView to show them. I have to show each image with its corresponding text next to it, and even though the texts show the images just won't work. I've been trying all solutions I could find around, but nothing seems to work. I would greatly appreciate some guidance.
This is the solution I'm trying atm:
Method I call from the class that extends ListActivity (both titles and imageurls are String[], imageurls contains the image url sources and titles contains the text to be shown next to the images)
setListAdapter(new MyPerformanceArrayAdapter(this, titles, imageurls)); And this is the code I have for MyPerformanceArrayAdapter:
public class MyPerformanceArrayAdapter extends ArrayAdapter<String> { private final Activity context; private final String[] names; private final String[] images; public MyPerformanceArrayAdapter(Activity context, String[] names, String[] images) { super(context, R.layout.rowlayout, names); this.context = context; this.names = names; this.images = images; } @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = context.getLayoutInflater(); View rowView = inflater.inflate(R.layout.rowlayout, null, true); TextView textView = (TextView) rowView.findViewById(R.id.label); ImageView imageView = (ImageView) rowView.findViewById(R.id.icon); String s = names[position]; textView.setText(s); Drawable drawable = LoadImageFromWebOperations(images[position]); imageView.setImageDrawable(drawable); return rowView; } private Drawable LoadImageFromWebOperations(String url) { try { InputStream is = (InputStream) new URL(url).getContent(); Drawable d = Drawable.createFromStream(is, "src name"); return d; } catch (Exception e) { System.out.println("Exc="+e); return null; } } } Thank you very much!