listview - Android Custom List View -
i have tried several methods tutorial , no 1 able solve prob yet.i trying sine 2 days. problem when run custom list view program shows error. , error
mainactivity:
public class mainactivity extends activity { listview list; string[]name={ "al fresco", "appeliano", "bfc", "mr. burger", "grind house", "comic cafe", "cafe 5six7", "cafe cheeze panic" }; integer[]imgid={ r.drawable.alfresco, r.drawable.appeliano, r.drawable.bfc, r.drawable.burger, r.drawable.tbk, r.drawable.comiccafe, r.drawable.cafefivesixseven, r.drawable.cafecheezepanic }; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); customadapter adapter=new customadapter(mainactivity.this,name,imgid); list=(listview)findviewbyid(r.id.list); list.setadapter(adapter); } }
and customadapter:
public class customadapter extends arrayadapter<string> { private final activity context; private final string[] name; private final integer[]imgid; public customadapter(activity context,string[] name, integer[] imgid) { super(context,r.layout.mylist, name); this.context = context; this.name = name; this.imgid = imgid; } @override public view getview(int position, view view, viewgroup parent) { layoutinflater inflater=context.getlayoutinflater(); view rowview=inflater.inflate(r.layout.mylist,null,true); textview txttitle= (textview) rowview.findviewbyid(r.id.item_name); imageview imageview= (imageview) rowview.findviewbyid(r.id.list_item); txttitle.settext(name[position]); imageview.setimageresource(imgid[position]); return rowview; } }
since haven't provide more info, details provided number 1 the appleiano.png image 1 causing issue.try using image time being example application icon , see if project builds.
this due adding image in drawable has extension like(.jpg) , have changed or saved .png format(this error occur while changing image format manually without using editor tool). android studio throws error while compiling resource package using aapt(android asset packaging tool), need use image editor tools "gimp or paint" save extension accordingly. rebuild project once done.
tip: if on mac os can open terminal , run following command images folder: 'sips -s format png *.png --out .' convert files .png sufix real png files
Comments
Post a Comment