Write item in a ListView Android -
i'm developing app. in app i'm stored information in class named promo in defined 4 strings , made 4 getter , setters. made class named promotions in defined array of promo. store data in promo model i'm doing so:
promo promo = new promo(); promo.setname("promozione"); promo.setdescription("la promozione può essere spesa"); promo.setdate("29 lug 2013"); promo.setimgurl("http://www.pensando.it/wp/wp-content/uploads/2012/11/coupon.jpg");
now in intent show field name in listview , when click on item of listview load intent in show details of promo. write name in listview made method in want read data array promo , display name of promotions in list item. made listadapter , pass class , array of promotions, says me should initialized array promotions. post here code i'm trying use display informations:
method loaddatafrommodel
private void loaddatafrommodel() { lvtitle = (listview) findviewbyid(r.id.lvtitle); final promotions[] promotions; listadapter latitle = new listadapter(archiveactivity2.class, promotions); lvtitle.setadapter(latitle); lvtitle.setonclicklistener(new adapterview.onitemclicklistener() { }); }
listadapter.java
import android.content.context; import android.widget.arrayadapter; import it.bitmama.interactv.r; import it.bitmama.interactv.model.promotions; public class listadapter extends arrayadapter<promotions> { public listadapter(context context, promotions[] promotions) { super(context, r.layout.list_item, r.id.tvtitle, promotions); } }
i post 2 class i'm using models:
promo.java
public class promo { string name; string description; string imgurl; string date; @override public string tostring() { return name.tostring(); } public string getname() { return name; } public void setname(string name) { this.name = name; } public string getdescription() { return description; } public void setdescription(string description) { this.description = description; } public string getimgurl() { return imgurl; } public void setimgurl(string imgurl) { this.imgurl = imgurl; } public string getdate() { return date; } public void setdate(string date) { this.date = date; } }
promotions.java
public class promotions { public promo[] promotions; }
now hope know what's i'm trying do, need display correctly informations. thank suggestion
create adapter:
private arrayadapter madapter;
private void loaddatafrommodel() {
lvtitle = (listview) findviewbyid(r.id.lvtitle); arraylist<promo> list = new arraylist<promo>(); arrayadapter madapter = new arrayadapter(getcontext() , r.id.lvtitle, list); lvtitle.setadapter(madapter); lvtitle.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { } });
}
modify members of adapter:
void onnewmember(promo promo) {
madapter.add(promo);
}
you may set members of array list before injection in loaddatafrommodel()
promo promo = new promo(); ... set properties wanted list.add(promo)
Comments
Post a Comment