0

スクロールレイアウトにいくつかの編集テキストがあります。下部にボタンがあります。

実際、ビューを開くたびに、最初のeditTextが自動的にフォーカスを要求します。ボタンにフォーカスを合わせてほしい。

私はこれを試しましたが、成功しませんでした:

final ScrollView s = (ScrollView)findViewById(R.id.ScrollView01);
    s.post(new Runnable() {
       public void run() {
             Button button =(Button) findViewById(R.id.SaveProfileEditingButton);
             button.requestFocus();
       }
    });

hlepありがとうございます。

4

2 に答える 2

1

AndroidManifest.xmlandroid:windowSoftInputMode="stateHidden"でアクティビティに設定して、キーボードを非表示にします(EditTextにフォーカスしているために開きます)。その後、他のビューに焦点が当てられる場合があります。


アップデート

final ScrollView s = (ScrollView)findViewById(R.id.ScrollView01);
s.post(new Runnable() {
       public void run() {
             EditText editText =(EditText) findViewById(R.id.yourEditText);
             (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE))
                   .hideSoftInputFromWindow(editText.getWindowToken(), 0);

             Button button =(Button) findViewById(R.id.SaveProfileEditingButton);
             button.setFocusable(true);
             button.requestFocus();
      }
});
于 2012-05-02T13:18:37.550 に答える
0

コードは機能していますが、どのようにチェックしたか、またはButtonにフォーカスを設定する意味は何ですか。動作しているかどうかを確認するには

boolean r = btn.requestFocus();
Log.i("Tag", String.valueOf(r));
于 2012-05-02T13:19:37.003 に答える