listview of image and text in Android -


i have button , when click on it, want show listview image & text (static text). how can this?

my code.. public class category extends listactivity {     button category;     textview selection;     private static final string[] country = { "iceland", "india", "indonesia",          "iran", "iraq", "ireland", "israel", "italy", "laos", "latvia",          "lebanon", "lesotho ", "liberia", "libya", "lithuania",          "luxembourg" };          private static final string[] curr = { "isk", "inr", "idr", "irr", "iqd",          "eur", "ils", "eur", "lak", "lvl", "lbp", "lsl ", "lrd", "lyd",          "ltl ", "eur"           };     /** called when activity first created. */     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.category);          category=(button)findviewbyid(r.id.category);            class efficientadapter extends baseadapter {              private layoutinflater minflater;               public efficientadapter(onclicklistener onclicklistener) {              minflater = layoutinflater.from((context) onclicklistener);               }               public int getcount() {              return country.length;              }               public object getitem(int position) {              return position;              }               public long getitemid(int position) {              return position;              }               public view getview(int position, view convertview, viewgroup parent) {              viewholder holder;              if (convertview == null) {              convertview = minflater.inflate(r.layout.listview, null);              holder = new viewholder();              holder.text = (textview) convertview              .findviewbyid(r.id.textview01);              holder.text2 = (textview) convertview              .findviewbyid(r.id.textview02);               convertview.settag(holder);              } else {              holder = (viewholder) convertview.gettag();              }               holder.text.settext(curr[position]);              holder.text2.settext(country[position]);               return convertview;              }               class viewholder {              textview text;              textview text2;              }              }         category.setonclicklistener(new view.onclicklistener() {             public void onclick(view v) {                  listview l1 = (listview) findviewbyid(r.id.listview);                  l1.setadapter(new efficientadapter(this));              }             });      }     } 

  • "r.layout.listview" in layout file ,which u r inflating in getview method, add 1 imageview.

  • now add imageview in view holder in place of second textview text2.

    class viewholder {       textview text;       imageview im2;   } 
  • do in getview:

    holder.im2 = (imageview) convertview              .findviewbyid(r.id.imageview02); 
  • in place of holder.text2.settext(country[position]);, set background image on imageview.

ex. holder.im2.setbackgrounddrawable(getresources().getdrawable(r.drawable.vimage));

thanks.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -