2011-08-11 50 views
0

我是BB開發的初學者。我創建了一個CustomListField,當我點擊一行時,該行的背景顏色必須改變,並且必須顯示一個新的屏幕(完成!)。如何在導航後更改ListField中的行顏色背景點擊?

任何人都可以幫我完成這件事嗎? THX

下面是代碼:

protected boolean navigationClick(int status, int time) 
     {Field field = this.getLeafFieldWithFocus(); 

     if(field instanceof ListField) 
     { 
     // listValues is String[] where you store your list elements. 
     // listField is the ListField instance you are using 
      UiApplication.getUiApplication().pushScreen(new ReadMsgScreen()); 

      int index= getIndex(); 
      if(index== this.getSelectedIndex()) 
      { 
       **// I think the code to change the row's background color must be set here!** 

      } 

      return true; 
     } 

     return super.navigationClick(status, time); 
    } 

回答

0

onerride在黑莓的paint()方法作爲顯示下面的代碼..

_specialNumbers = new LabelField(Constants.SPECIAL_NUMBERS,LabelField.USE_ALL_WIDTH) { 
      protected void paintBackground(Graphics arg0) { 
       int color = arg0.getBackgroundColor(); 
       arg0.setBackgroundColor(Color.LIGHTGREY); 
       arg0.clear(); 
       arg0.setBackgroundColor(color); 
      } 
     }; 
+0

我需要調用ListField行的paint()方法。 'int index = getIndex();我嘗試覆蓋paint()方法:我試圖覆蓋paint()方法:如果(索引== this.getSelectedIndex()) ** //我認爲改變行的背景顏色的代碼必須在這裏設置** ** }' – Manel

+0

我試圖覆蓋paint 'TableRowManager ele_row =新TableRowManager() \t \t \t { \t \t \t \t保護無效塗料(圖形圖像){ \t \t \t \t \t無效(); \t \t \t \t \t graphics.setBackgroundColor(Color.RED); \t \t \t \t \t super.paint(graphics); \t \t \t \t} \t \t \t};; '但它仍然不工作!有沒有人有關於如何更改列表字段中某一行的背景顏色的想法? – Manel

+0

此問題的解決方案是添加'g.setBackgroundColor(0x33CCFF); g.clear();'在'subpaint(g)'之前的'drawRow(Graphics g,int x,int y,int width,int height)'方法''這是孔方法:'public void drawRow(Graphics g,int x,int y,int width,int height){layout(width,height); setPosition(x,y); g.pushRegion(getExtent()); g.setBackgroundColor(0x33CCFF); g.clear(); g.setColor(Color.BLACK); subpaint(g); g.drawLine(0,0,getPreferredWidth(),0); g.popContext();}' – Manel

1

利用這一點,一定會工作...

int tmpcolor = graphics.getColor(); 
graphics.setColor(Color.CYAN); 
graphics.fillRect(0, y, width, getRowHeight()); 
graphics.setColor(tmpcolor); 

謝謝...

0

在您的CustomListField的ListFieldCallback的drawListRow()方法中,以不同方式繪製所選行,並調用Transition以緩慢顯示其他屏幕。