I Create a Activity Extends ListActivity I can used SimpleAdapter to display R.drawable.picture but I want to display picture from web in CustomerItem How do?
List data; List> plan_list;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.plan_list);
plan_list = getPlanList();
Plan_SimpleAdapter adapter = new Plan_SimpleAdapter(this, plan_list,
R.layout.plan_item, new String[] { "Title", "miaoshu","img" }, new int[] {
R.id.textView1,R.id.miaoshu, R.id.plan_logo });
setListAdapter(adapter);
}
// return plan list
private List<Map<String, Object>> getPlanList() {
plan_list = new ArrayList<Map<String, Object>>(3);
Map<String, Object> map = new HashMap<String, Object>();
map.put("Title", "Android");
map.put("miaoshu","M");
map.put("img", "http://www.deakin.edu.au/conferences/icpads2008/images/deakin_logo.png");
plan_list.add(map);
map = new HashMap<String, Object>();
map.put("Title", "Lenovo");
map.put("miaoshu", "N");
map.put("img", R.drawable.planlogo);
plan_list.add(map);
map = new HashMap<String, Object>();
map.put("Title", "Droid");
map.put("miaoshu", "O");
map.put("img", R.drawable.planlogo);
plan_list.add(map);
return plan_list;
}
public class Plan_SimpleAdapter extends SimpleAdapter {
public Plan_SimpleAdapter(Context context,
List<? extends Map<String, ?>> data, int resource, String[] from,
int[] to) {
super(context, data, resource, from, to);
// TODO Auto-generated constructor stub
}
@Override
public void setViewImage(ImageView v, String value) {
// TODO Auto-generated method stub
try {
URL url = new URL(value);
URLConnection conn = url.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
Bitmap bm = BitmapFactory.decodeStream(is);
v.setImageBitmap(bm);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
super.setViewImage(v, value);
}
}