Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

android - ListView color issue -


hey i'm not professional coder stretch, i've been playing around simple to-do list learn basics of android development.

i've been able want working, there 1 problem listview has me totally stumped. i've extended simplecursoradapter in order format data coming sqlite database , change color of duedate text based on whether or not duedate has expired. formatting works flawlessly, i'm getting odd results colors.

the first few entries in listview expect them to, scroll down, inconsistencies start popping items no due date set colored red or green. more scroll , down in list, more inconsistencies appear until every row colored whether should or not.

can me understand going on here? please see custom adapter below.

public class proadapter2 extends simplecursoradapter {   private static int[] = {r.id.priority, r.id.projectname, r.id.duedate};   private static string[] = {"priorities", "projectname", "duedate"};   private context context;   private int layout;    //constructor   public proadapter2(context context, int layout, cursor c) {     super(context,layout, c, from, to);     this.context=context;     this.layout = layout;   }        @override   public view newview(context context, cursor curso, viewgroup parent){     cursor c = getcursor();     final layoutinflater inflater = layoutinflater.from(context);     view v = inflater.inflate(layout, parent, false);     textview txtname = (textview) v.findviewbyid(r.id.projectname);     txtname.settext(c.getstring(1));     textview txtpriority = (textview) v.findviewbyid(r.id.priority);     txtpriority.settext(c.getstring(2));      return v;   }       @override   public void bindview(view v, context context, cursor c) {     textview txtduedate = (textview) v.findviewbyid(r.id.duedate);     textview txtduedatelabel = (textview) v.findviewbyid(r.id.duedate_label);     textview txtpriority = (textview) v.findviewbyid(r.id.priority);     textview txtprioritylabel = (textview) v.findviewbyid(r.id.priority_label);     textview txtname = (textview) v.findviewbyid(r.id.projectname);      linearlayout pridate = (linearlayout) v.findviewbyid(r.id.pridate);      string duedate = c.getstring(3);     string cdate = c.getstring(4);     string duedateformated;       mytime t = new mytime();      long ctimelong = c.getlong(6);      long dtimelong = c.getlong(5);       duedateformated = t.getformatedtime(c.getstring(3));           txtduedate.settext(duedateformated);       if (c.getint(5)==0){         txtduedate.settext("not set");      }      else if (ctimelong < dtimelong){                 txtduedate.settextcolor(color.green);      }      else if (ctimelong > dtimelong){         txtduedate.settextcolor(color.red);     }   } } 

image http://i.stack.imgur.com/bt4z8.png

the simplest solution add following after txtduedate.settext("not set");:

txtduedate.settextcolor(color.black); 

the reason listview recycles view objects create in newview method.

so when bindview called, v parameter isn't shiny-new view object, in fact 1 top of list isn't visible more, , had green or red text.

so need make sure explicitly set properties require, including text colour.

aside that, there further optimisations can make. example, shouldn't calling settext in newview method — should in bind method.

for info how listview works, can watch talk or @ pdf slides:
http://www.google.com/events/io/2010/sessions/world-of-listview-android.html


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -