android - Wrong backgroundcolor on ListView inflate -


so have listview uses custom adapter. want background color of item either red or green, depending on value out of database getdbvalue(); (this works).

the problem is, when activity first opened, , listview inflated, listview items have same (not correct) green background color. when start scrolling though, background set correctly.

how right background color when listview inflates , program "error"?

i have debugged , dbvalue returning correct value.

this code:

public view getview(int position, view convertview, viewgroup parent) {     return createviewfromresource(position, convertview, parent, mresource); }  private view createviewfromresource(int position, view convertview,         viewgroup parent, int resource) {     view v;      if (convertview == null) {         // first time views created         v = minflater.inflate(resource, parent, false);     } else {         v = convertview;     }      string dbvalue = getdbvalue();      if(!dbvalue.equals("me")){             v.setbackgroundcolor(color.argb(230, 255, 0x00, 0x00));     }else{             v.setbackgroundcolor(color.argb(230, 0x00, 255, 0x00));     }      setviewtext((textview) v, text);      return v; } 

i done thing in app,

please make drawable that, , apply in view, here share method set drawable, check it.

please call method in createviewfromresource so, work.

@suppresslint("newapi") @suppresswarnings("deprecation") private void setdrwable(drawable drawable,view view) {     if(build.version.sdk_int>=16)     {         view.setbackground(drawable);     }     else     {         view.setbackgrounddrawable(drawable);     } } 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -