2010-12-22 65 views
0

這是怎樣的一個重新發布的,而我對任何損壞的規則道歉,但我有幾個有關軟鍵盤的Android手機問題:一對夫婦的Android軟鍵盤問題

1)我有一個Android應用有幾個不同的視圖(用戶之間切換)。我如何確定當前視圖是哪個?我需要獲取當前視圖來執行隱藏虛擬鍵盤的代碼。

2)如何檢查當前是否顯示虛擬鍵盤(這樣我可以過濾各種硬鍵的動作)?

感謝, R.

回答

0

1) 公共類ViewIdentification擴展活動實現OnFocusChangeListener {

EditText _edt1; 
EditText _edt2; 
EditText _edt3; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    _edt1 = (EditText)findViewById(R.id.EditText01); 
    _edt1.setOnFocusChangeListener(ViewIdentification.this); 
    _edt2 = (EditText)findViewById(R.id.EditText02); 
    _edt2.setOnFocusChangeListener(ViewIdentification.this); 
    _edt3 = (EditText)findViewById(R.id.EditText03);  
    _edt3.setOnFocusChangeListener(ViewIdentification.this); 


} 

@Override 
public void onFocusChange(View v, boolean hasFocus) { 
    // TODO Auto-generated method stub 

     if(v == _edt1 && hasFocus == true){ 

     Toast.makeText(ViewIdentification.this, "The First EditText is focused now", Toast.LENGTH_LONG).show(); 

     }else if(v == _edt2 && hasFocus == true){ 

     Toast.makeText(ViewIdentification.this, "The Second EditText is focused now", Toast.LENGTH_LONG).show(); 

     }else if(v == _edt3 && hasFocus == true){ 

     Toast.makeText(ViewIdentification.this, "The Third EditText is focused now", Toast.LENGTH_LONG).show(); 

     } 

} 

}

注意:這樣,我們可以知道哪種說法是重點。

2)

這可以通過計算活性(在其中最後聚焦的視圖是在該位置處)的大小來進行。