2012-06-11 109 views
1

我無法將焦點設置爲具有兩個LabelFieldsHorizontalFieldManager。我想在焦點時突出顯示HorizontalFieldManager。我正在使用下面的代碼,但它不工作。無法將焦點設置爲Horizo​​ntalFieldManager

HorizontalFieldManager hrzMgrTimeLabel = new HorizontalFieldManager(
     Manager.USE_ALL_HEIGHT|Manager.FOCUSABLE) { 

    protected void onFocus(int direction) { 
     focussed = true; 
     invalidate(); 
     super.onFocus(direction); 
    } 

    protected void onUnfocus() { 
     focussed = false; 
     invalidate(); 
     super.onUnfocus(); 
    } 

    protected void paint(Graphics g) { 
     g.setBackgroundColor(0x646060); 
     if (focussed) { 
      g.setColor(Color.BLUE); 
     } 
     g.clear(); 
     super.paint(g); 
    } 
}; 

hrzMgrTimeLabel.add(a); 
hrzMgrTimeLabel.add(b); 

horizontalFieldManager_left15.add(hrzMgrTimeLabel); 

下面是執行的LabelField。

final LabelField a= new LabelField("") { 
    protected void paint(Graphics graphics) { 
     graphics.setColor(Color.WHITE); 
     graphics.setBackgroundColor(0x646060); 
     graphics.clear(); 
     super.paint(graphics); 
    } 
}; 

final LabelField b= new LabelField("") { 
    protected void paint(Graphics graphics) { 
     graphics.setColor(Color.WHITE); 
     graphics.setBackgroundColor(0x646060); 
     graphics.clear(); 
     super.paint(graphics); 
    } 
}; 
+0

更新你的問題,你可以使用一些圖像來解釋你想達到什麼。 – Rupak

+0

我有兩個labfetields,其中一個數據是7,另一個是我正在添加到HFM中的數據,我想關注它。 – harqs

+0

聚焦時,您是否需要更改Horizo​​ntalFieldManager的背景顏色? – Rupak

回答

0

如果您想要關注標籤字段,請使用final LabelField a= new LabelField("".FOCUSABLE)

+0

我已經添加了HFM的標籤字段,我想集中整個HFM – harqs

+0

,如果我讓兩個labelfield都可以聚焦但都不是整體,我將重點放在每個labelfield – harqs

+0

上,您想突出顯示該時區或爲編輯目的? –

0

您需要在HorizontalFieldManager上至少有一個可對焦區域。以下行將做到這一點。

hrzMgrTimeLabel.add(new NullField(NullField.FOCUSABLE)); 

請檢查以下代碼。

HorizontalFieldManager hrzMgrTimeLabel = new HorizontalFieldManager(Manager.USE_ALL_HEIGHT | Manager.FOCUSABLE) { 
    protected void paint(Graphics g) { 
     g.setBackgroundColor(isFocus() ? Color.BLUE : 0x646060); 
     g.clear(); 
     super.paint(g); 
    } 

    protected void onFocus(int direction) { 
     invalidate(); 
     super.onFocus(direction); 
    } 

    protected void onUnfocus() { 
     invalidate(); 
     super.onUnfocus(); 
    } 

    protected boolean navigationMovement(int dx, int dy, int status, int time) { 
     invalidate(); 
     return super.navigationMovement(dx, dy, status, time); 
    } 

    protected boolean navigationClick(int status, int time) { 
     invalidate(); 
     return super.navigationClick(status, time); 
    } 

    protected boolean navigationUnclick(int status, int time) { 
     invalidate(); 
     return super.navigationUnclick(status, time); 
    } 
}; 

final LabelField a = new LabelField("First Label Field") { 
    protected void paint(Graphics graphics) { 
     graphics.setColor(Color.WHITE); 
     super.paint(graphics); 
    } 
}; 

final LabelField b = new LabelField("Second Label Field") { 
    protected void paint(Graphics graphics) { 
     graphics.setColor(Color.WHITE); 
     super.paint(graphics); 
    } 
}; 

hrzMgrTimeLabel.add(new NullField(NullField.FOCUSABLE)); 
hrzMgrTimeLabel.add(a); 
hrzMgrTimeLabel.add(b); 

onFocus(...)onUnfocus()navigationMovement(...)navigationClick(...)navigationUnclick(...) - 這些方法只是對overrided刷新繪圖。

+0

她只是要求讓經理專注於其他領域,而不是在那位經理那裏集中精力。如果添加空字段只是解決方案,那麼navigationMovement,navigationClick的目的是什麼,在這裏。不必要的複雜解決方案。 – jeet

+0

如果你不明白'navigationMovement','navigationClick'等的用途,那麼你可以問一個解釋,但你應該怎麼知道這些是不必要的?並且增加可調焦的'NullField'並不是這裏唯一的改變。仔細閱讀代碼。 – Rupak

+0

您是否檢查過您的代碼,如果它按照要求工作,並且我知道這些方法是不必要的,原因是這些方法在超級調用中失效,invalidate將再次調用paint方法,但它會更改爲什麼油漆,不清楚,導致重點是NullField不在HFM上。 – jeet

1

getFocusRect()函數可能會給你答案。 它提供了在管理器中應用焦點的程度,然後可以使用Graphics.paint()方法或Border類。

+0

您能否請您解釋一下適用於我的代碼的代碼段,我不清楚 – harqs