java - Integrating Picasso into List View with custom adapter that has a Hashmap -
so im trying add images list view of mine, proving pain. use picasso, images requested via http.
i can add string objects textviews in list view. thats easy part. however, had crack @ trying images follows;
mainactivity.java
... hashmap<string, string> map = new hashmap<string, string>(); map.put("name", name); map.put("title", title); map.put("image_url",image_relative_url+image_url+".png"); championlist.add(map); // listview object xml final listview listview = (listview) findviewbyid(r.id.listview); listadapter adapter = new simpleadapter(mainactivity.this, championlist, r.layout.list_view_row, new string[]{"name","title"}, new int[]{r.id.name, r.id.title}); //listadapter adapter = new customlist(mainactivity.this,new string[]{"name"}, new string[]{"title"}, new string[]{"image_url"}) listview.setadapter(adapter); listview.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { hashmap<string,string> map = (hashmap<string,string>)listview.getitematposition(position); string name= map.get("name"); string image= map.get("image_url"); log.i("summoner",name+image); //display in long period of time toast.maketext(getapplicationcontext(), name, toast.length_long).show(); } }); ...
customlist.java
public class customlist extends arrayadapter<string> { private final activity context; private final string[] name; private final string[] title; private final string[] image_url; public customlist(activity context, string[] name, string[] title, string[] image_url) { super(context, r.layout.list_view_row, name); this.context = context; this.name = name; this.title = title; this.image_url = image_url; } @override public view getview(int position, view view, viewgroup parent) { layoutinflater inflater = context.getlayoutinflater(); view rowview= inflater.inflate(r.layout.list_view_row, null, true); textview txttitle = (textview) rowview.findviewbyid(r.id.name); txttitle.settext(name[position]); textview txtname = (textview) rowview.findviewbyid(r.id.title); txtname.settext(title[position]); imageview imageview = (imageview) rowview.findviewbyid(r.id.img); picasso.with(this.context).load(image_url[position]).into(imageview); return rowview; } }
help largely appreciated.
where did go wrong? lost way, somewhere along in bitterness
modify adapter extend baseadapter. use picasso.with(this.context).load(championlist.get(position).get("image_url")).into(imageview) load image.
Comments
Post a Comment