0

これは一種の再投稿であり、ルールが破られたことをお詫びしますが、Android携帯のソフトキーボードについていくつか質問があります。

1)いくつかの異なるビュー(ユーザーが切り替える)を備えたAndroidアプリがあります。現在のビューがどれであるかをどのように判断できますか?仮想キーボードを非表示にするコードを実行するには、現在のビューを取得する必要があります。

2)仮想キーボードが現在表示されているかどうかを確認するにはどうすればよいですか(さまざまなハードキーのアクションをフィルタリングできます)??

ありがとう、R。

4

1 に答える 1

0

1) public class ViewIdentification extends Activity implements 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)

これは、アクティビティのサイズ (最後にフォーカスされたビューの位置) を計算することで実行できます。

于 2011-08-25T13:21:23.433 に答える