我是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);
}
我需要調用ListField行的paint()方法。 'int index = getIndex();我嘗試覆蓋paint()方法:我試圖覆蓋paint()方法:如果(索引== this.getSelectedIndex()) ** //我認爲改變行的背景顏色的代碼必須在這裏設置** ** }' – Manel
我試圖覆蓋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
此問題的解決方案是添加'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