Image and text displays separately in listview-Android Using Image Loader -
i trying load image , text via url using imageloader when populate in listview image , text separated when displaying
here code
mall=getintent().getstringarraylistextra("text"); mallpos=getintent().getstringarraylistextra("ima"); system.out.println("images"+mallpos); system.out.println(mall.size()); for(int i=0;i<mall.size();i++) { poss=mall.get(i); system.out.println("value"+poss); dto =new locationdto(); dto.setmallname(poss); rou.add(dto); } system.out.println(mallpos.size()); for(int i=0;i<mallpos.size();i++) { ima=mallpos.get(i); system.out.println("value"+ima); dto=new locationdto(); dto.setimage(ima); system.out.println("imaghe"+ dto.getimage()); rou.add(dto); } lv=(listview)findviewbyid(r.id.listm); system.out.println("arraysize#############" + rou.size()); system.out.println("arraysize#############" + rou1.size()); materialmasteradapter adapteer =new materialmasteradapter(malllistactivity.this, rou); lv.setadapter(adapteer);
here adapter code,i couldn't rectify error
import com.nostra13.universalimageloader.core.imageloader; import com.nostra13.universalimageloader.core.imageloaderconfiguration; import android.content.context; import android.graphics.bitmap; import android.graphics.bitmapfactory; import android.os.asynctask; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.baseadapter; import android.widget.imageview; import android.widget.textview; public class materialmasteradapter extends baseadapter { holder mholder = null; private context mcontext; locationdto dto = new locationdto(); arraylist<locationdto> a1; arraylist<locationdto> arr =new arraylist<locationdto>(); string a2; string[] imageurl=null; imageloader imageloader; string s; string urlss; public materialmasteradapter(context c,arraylist<locationdto> arrlist1 ) { // todo auto-generated constructor stub mcontext=c; a1=arrlist1; imageloader.getinstance().init(imageloaderconfiguration.createdefault(mcontext)); } public int getcount() { // todo auto-generated method stub return a1.size(); } public object getitem(int position) { // todo auto-generated method stub return a1.get(position); } public long getitemid(int position) { // todo auto-generated method stub return position; } public view getview(int pos, view child, viewgroup parent) { // todo auto-generated method stub holder mholder; layoutinflater layoutinflater; if (child == null) { layoutinflater = (layoutinflater) mcontext.getsystemservice(context.layout_inflater_service); child = layoutinflater.inflate(r.layout.list_layout, null); mholder = new holder(); mholder.txtitemid = (textview) child.findviewbyid(r.id.artist); mholder. imageview = (imageview) child.findviewbyid(r.id.list_image); child.settag(mholder); } else { mholder = (holder) child.gettag(); } dto=a1.get(pos); string url=dto.getimage(); mholder.txtitemid.settext(dto.getmallname()); imageloader.getinstance().displayimage(url, mholder.imageview); return child; } public class holder { textview txtitemid,txtmat,txtqty,image; imageview imageview; } }
your posted code didn't gave proper info per understanding can follow this. in view method of adapter define text view , image view. while calling adapter send data contains both image , text. see this.
public class myitemsadapter { arraylist<uploaditem> datalist; context context; public myitemlistadapter2(arraylist<uploaditem> list,context con){ this.datalist = list; this.context = con; imageloaderconfiguration config = new imageloaderconfiguration.builder(context).build(); imageloader.getinstance().init(config); im = imageloader.getinstance(); } @override public int getcount() { return datalist.size(); } @override public object getitem(int arg0) { return null; } @override public long getitemid(int arg0) { return arg0; } @override public view getview(int position, view convertview, viewgroup parent) { final uploaditem thisitem = datalist.get(position); if(convertview == null){ convertview = inflater.inflate(r.layout.my_item_list_row2, parent,false); textview text = (textview) convertview.findviewbyid(r.id.text); imageview image = (imageview_ convertview.findviewbyid(r.id.image); string path = thisitem.get(position).getimagepath(); im.displayimage(path, image); text.settext(thisitem.getdescritption()); } }
call adapter sending required data. , set list view. here using universal image loader load images asynchronously..you use other loader per wish hope helps
Comments
Post a Comment