Set BlackBerry image field on focus (Highlighting) color -
i'm developing blackberry application uses table row manager create table view. in application added bitmap fields row backgrounds, , default blue color of field highlighting gone. read answers in stackoverflow , implemented code try make highlight in default color:
//adds background image final bitmap bck; bck = bitmap.getbitmapresource("inner-back-stripe.jpg"); bitmapfield backgrnd = new bitmapfield(bck,bitmapfield.focusable){ protected void drawfocus(graphics graphics, boolean on) { setspace(5, 5); super.drawfocus(graphics, on); } };
but still having same problem, rows not highlighted, texts changes white color when scrolling.
sample row background:
here paste whole code have used
public class leavedetails extends listfield implements listfieldcallback { tablerowmanager row; vector rows; private string[] arrdnames = {"udith","mohammadu","rajaram","david"}; private string[] arrdate = {"12-jan-2013","17-feb-2013","20-mar-2013","14-may-2013"}; private string[] arrtype = {"medical leave","annual leave","medical leave","annual leave"}; private int[] arrcount = {3,5,2,6}; public leavedetails(){ super(0, listfield.multi_select); setrowheight(100); setemptystring("", drawstyle.hcenter); setcallback(this); rows = new vector(); (int x = 0; x < 4; x++) { row = new tablerowmanager(); //adds background image final bitmap bck; bck = bitmap.getbitmapresource("inner-back-stripe.jpg"); bitmapfield backgrnd = new bitmapfield(bck,bitmapfield.focusable){ protected void drawfocus(graphics graphics, boolean on) { setspace(5, 5); super.drawfocus(graphics, on); } }; row.add(backgrnd); //bitmapfield backgrnd = new bitmapfield(bitmap.getbitmapresource("inner-back-stripe.jpg"),field.focusable); //row.add(backgrnd); //field 0 //adds names labelfield lfname = new labelfield(string.valueof(arrdnames[x]),field_hcenter); lfname.setfont(lfname.getfont().derive(font.bold,30)); row.add(lfname);//field 1 //adds date labelfield date = new labelfield("applied on : "+arrdate[x]); row.add(date);//field 2 //adds type labelfield type = new labelfield("leave type : "+arrtype[x]); row.add(type);//field 3 //adds duration in numbers labelfield lfcountnotifications = new labelfield(string.valueof(arrcount[x]),field_hcenter); lfcountnotifications.setfont(lfcountnotifications.getfont().derive(font.bold,72)); row.add(lfcountnotifications);//field 4 //adds word "duration" labelfield lfnewnotification = new labelfield("duration/days",field.field_hcenter); lfnewnotification.setfont(lfnewnotification.getfont().derive(font.georgian_script,30)); row.add(lfnewnotification);//field 5 //adds right arrow image bitmapfield showmore = new bitmapfield(bitmap.getbitmapresource("more.png")); row.add(showmore);//field 6 //adds rows table rows.addelement(row); }//end of loop setsize(rows.size()); } // listfieldcallback implementation public void drawlistrow(listfield listfield, graphics g, int index, int y,int width) { leavedetails list = (leavedetails) listfield; tablerowmanager rowmanager = (tablerowmanager) list.rows.elementat(index); rowmanager.drawrow(g, 0, y, width, list.getrowheight()); } //tracks field click event protected boolean trackwheelclick(int status, int time) { int index = getselectedindex(); switch (index) { case 0: dialog.inform(index+" clicked"); break; case 1: dialog.inform(index+" clicked"); break; case 2: dialog.inform(index+" clicked"); break; case 3: dialog.inform(index+" clicked"); break; default: dialog.inform("error!"); break; } return true; } private class tablerowmanager extends manager { public tablerowmanager() { super(0); } // causes fields within row manager layed out // painted. public void drawrow(graphics g, int x, int y, int width, int height) { // arrange cell fields within row manager. layout(width, height); // place row manager within enclosing list. setposition(x, y); // apply translating/clipping transformation graphics // context row paints in right area. g.pushregion(getextent()); // paint manager's controlled fields. subpaint(g); // restore graphics context. g.popcontext(); } // arrages manager's controlled fields left right within // enclosing table's columns. protected void sublayout(int width, int height) { // set size , position of each field. int fontheight = font.getdefault().getheight(); int preferredwidth = getpreferredwidth(); //field background image field field = getfield(0); layoutchild(field, 640, 166); setpositionchild(field, 0, 0); // name field = getfield(1); layoutchild(field, 640, fontheight+4); setpositionchild(field, 0, 5); // date field = getfield(2); layoutchild(field, 500, fontheight+4); setpositionchild(field, 0, 30); //type field = getfield(3); layoutchild(field, 500, fontheight+1); setpositionchild(field, 0, 60/*fontheight+6*/); //duration number field = getfield(4); layoutchild(field, 100, 100); setpositionchild(field, 450, 5); //"duration" word field = getfield(5); layoutchild(field, 300, 100); setpositionchild(field, 400, 62); //more image field = getfield(6); layoutchild(field, 100, 100); setpositionchild(field, 575, 20); setextent(preferredwidth, getpreferredheight()); } // preferred width of row defined list renderer. public int getpreferredwidth() { return 640; } // preferred height of row "row height" defined in // enclosing list. public int getpreferredheight() { return getrowheight(); } } public object get(listfield listfield, int index) { return null; } public int getpreferredwidth(listfield listfield) { return 0; } public int indexoflist(listfield listfield, string prefix, int start) { return 0; } }
does body have idea happened here? want make highlight in default blue color. i'm new blackberry.
i think problem here has fact code uses bitmapfield
produce background. suggest couple other ways it, fix row focus problem.
1. if background must bitmap
sometimes, necessary. if have complicated background design, or special gradient, may need background image. that, still remove bitmapfield
. so, remove code:
final bitmap bck; bck = bitmap.getbitmapresource("inner-back-stripe.jpg"); bitmapfield backgrnd = new bitmapfield(bck,bitmapfield.focusable){
do not call add(backgrnd)
, , in sublayout()
method, remove this:
field field = getfield(0); layoutchild(field, 640, 166); setpositionchild(field, 0, 0);
and finally, remember change field index values in sublayout()
method lays out other fields (index 1-6 -> 0-5).
then, create bitmap background 1 line of code in list's constructor:
public leavedetails(){ super(0, listfield.multi_select); setrowheight(100); setemptystring("", drawstyle.hcenter); setcallback(this); setbackground(backgroundfactory.createbitmapbackground(bitmap.getbitmapresource("inner-back-stripe.jpg")));
now, create background entire listfield
, not 1 row. but, in case, should work, background solid green color.
2. avoiding bitmaps completely
in situation, not recommend bitmap @ all. you're using space in app, , hurting performance (slightly) using bitmap, when want solid color background. so, remove code told remove above, , instead of setbackground()
call showed in last code snippet, use this:
public leavedetails(){ super(0, listfield.multi_select); setrowheight(100); setemptystring("", drawstyle.hcenter); setcallback(this); setbackground(backgroundfactory.createsolidbackground(0xbdce66));
0xbdce66
looks hex color code green showed in question.
row separators
in original question, showed white separator bars between rows. first 2 solutions won't give that. but, can add separators either, adding few lines drawlistrow()
method:
public void drawlistrow(listfield listfield, graphics g, int index, int y,int width) { leavedetails list = (leavedetails) listfield; tablerowmanager rowmanager = (tablerowmanager) list.rows .elementat(index); rowmanager.drawrow(g, 0, y, width, list.getrowheight()); // draw separator of given color (e.g. white) int oldcolor = g.getcolor(); g.setcolor(color.white); int h = getrowheight(); //g.drawline(0, y+h-1, width, y+h-1); // 1 pixel thick line g.fillrect(0, y+h-3, width, 3); // 3 pixel thick "line" g.setcolor(oldcolor); }
results
note: right side of each row hidden because tested on 360px wide screen, , code hard-codes field locations. so, they're off right side of screen. has nothing focus highlighting problem, though.
Comments
Post a Comment