2011-05-09 58 views
0

如何放置在經理bitmapFields而它的一些按鈕獲得focus.I移除位嘗試下面的代碼,但它不是working.`設置和按鈕的onfocus和onUnfocus

時「按鈕」獲得焦點我需要在Vfm中的按鈕旁邊添加「field1」。

button = new ImgButtonField("res/images/trans.png", Field.FOCUSABLE){ 
      protected void onFocus(int direction) { 
       Vfm.insert(field1, button.getIndex()) ; 
        super.onFocus(direction); 
        invalidate(); 
       } 
      protected void onUnfocus() { 
        Vfm.delete(field1); 
        super.onUnfocus(); 
        invalidate(); 
      }  
     }; 

回答

0

嘗試使用加,而非嵌入,示例代碼我試圖

ButtonField button,button1; 
LabelField field1; 
VerticalFieldManager vfm; 
public MyScreen() 
{   
    // Set the displayed title of the screen  
    setTitle("MyTitle"); 
    vfm=new VerticalFieldManager(); 
    field1=new LabelField("Sample"); 
    button=new ButtonField("Sample"){ 

     protected void onFocus(int direction) { 
       vfm.add(field1); 
       super.onFocus(direction); 
       invalidate(); 
       } 
      protected void onUnfocus() { 
        vfm.delete(field1); 
       super.onUnfocus(); 
       invalidate(); 
      }  

    }; 
    button1=new ButtonField("Sampl1"); 
    this.add(button1); 
    this.add(button); 
    this.add(vfm); 

} 

問候 勒凱什Shankar.P

0

嘗試放置NullField在管理器作爲佔位符。 NullField將不可見。在焦點上,您可以用field1替換該NullField。

NullField myNullField = new NullField(); 
    button = new ImgButtonField("res/images/trans.png", Field.FOCUSABLE){ 
       protected void onFocus(int direction) { 
         Vfm.replace(myNullField, field1) ; 
         super.onFocus(direction); 
         invalidate(); 
        } 
       protected void onUnfocus() { 
         Vfm.replace(field1, myNullField); 
         super.onUnfocus(); 
         invalidate(); 
       }  
      }; 
    //add fields to Vfm, including the myNullField placeholder.