android - Base Adapter Position on Scroll -


i have adapter shows items list retrieved web service, upon scrolling it's inflating first position layout (it's considering first visible item having position 0 not right), please help.

here's adapter:

private class hwlistarrayadapter extends baseadapter {       private arraylist<homework> items;     private final activity context;      public hwlistarrayadapter(activity context, arraylist<homework> items) {          this.context = context;         this.items = items;     }      @override     public int getcount() {         return items.size() + 1;     }      @override     public object getitem(int position) {         return items.get(position);     }      @override     public long getitemid(int position) {         return position;     }      @override     public view getview(int position, view view, viewgroup viewgroup) {         view v = view;         textview desc, date, course;         if (position == 0) {              layoutinflater vi;             vi = layoutinflater.from(context);             v = vi.inflate(r.layout.homework_list_top, null);              abslistview.layoutparams params = new abslistview.layoutparams(abslistview.layoutparams.match_parent, (int) (myapplication.screenheight * 0.05));             v.setlayoutparams(params);         } else {             if (v == null) {                 layoutinflater vi;                 vi = layoutinflater.from(context);                 v = vi.inflate(r.layout.homework_list_item, null);             }             abslistview.layoutparams params = new abslistview.layoutparams(abslistview.layoutparams.match_parent, (int) (myapplication.screenheight * 0.6) / 8);             v.setlayoutparams(params);               desc = (textview) v.findviewbyid(r.id.descriptionhw);             desc.settypeface(myapplication.dinar);             desc.settext(items.get(position - 1).getdetails());              course = (textview) v.findviewbyid(r.id.coursehw);             course.settypeface(myapplication.dinar);             course.settext(items.get(position - 1).getcoursename());              date = (textview) v.findviewbyid(r.id.datehw);             date.settypeface(myapplication.dinar);             date.settext(dateconverter(items.get(position - 1).getduedate()));           }         return v;     } } 

you have override getviewtypecount , getitemviewtype 2 different convertviews. e.g.

@override public int getviewtypecount() {     return 2; }  @override public int getitemviewtype(int position) {     return position == 0 ? 0 : 1; } 

getviewtypecount says want handle 2 different type of rows, , getitemviewtype returns actual type. aware return type of getitemviewtype used internally android address array of view, sure return value between 0 , getviewtypecount() -1


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -