Редактировать текстовый фокус в Android - PullRequest
4 голосов
/ 03 ноября 2011

В моем приложении у меня есть текст для редактирования следующим образом.

EditText1   EditText2
EditText3   EditText4
EditText5   EditText6

в XML я объявил android:imeOptions="actionNext", а также я пишу

          editText1.setOnEditorActionListener(new EditText.OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                // TODO Auto-generated method stub
                 if (actionId == EditorInfo.IME_ACTION_DONE ||   actionId == EditorInfo.IME_ACTION_NEXT) {
                     editText2.requestFocus();

                  return false;
                  }
                return false;
            }
         });

Теперь на виртуальной клавиатуре в редактируемом тексте 1, если я нажимаю «Далее», я получаю фокус на редактируемый текст3 вместо editText2 и т. Д.

Как я могу сфокусироваться на EditText2 вместо edittext3 для моего пользователя приложения только нажмите «Далее или готово», он никогда не идет на трекбол.

Ответы [ 3 ]

4 голосов
/ 03 ноября 2011

Вы можете попробовать добавить атрибут android:nextFocusDown в ваш EditTexts.

1 голос
/ 03 ноября 2011

Я только что проверил ваш код со следующим макетом, и он работал как положено. (Ожидается = нажатие следующей на виртуальной клавиатуре, фокус которой был передан editText2)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_gravity="center"
android:padding="15dip">
<LinearLayout android:orientation="vertical"
    android:layout_height="wrap_content" android:layout_width="fill_parent"
    android:layout_gravity="center" android:paddingLeft="20dip"
    android:paddingRight="20dip">
    <TableLayout android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:layout_gravity="center"
        android:stretchColumns="*">

        <TableRow>
            <EditText android:id="@+id/edt1" />
            <EditText android:id="@+id/edt2" />
        </TableRow>

        <TableRow>
            <EditText android:id="@+id/edt3" />
            <EditText android:id="@+id/edt4" />
        </TableRow>

        <TableRow>
            <EditText android:id="@+id/edt5" />
            <EditText android:id="@+id/edt6" />
        </TableRow>


    </TableLayout>
</LinearLayout>

Вот также источник

package com.stackoverflow.test;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.KeyEvent;
    import android.view.inputmethod.EditorInfo;
    import android.widget.EditText;
    import android.widget.TextView;

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

    EditText editText1 = (EditText)findViewById(R.id.edt1);
    final EditText editText2 = (EditText)findViewById(R.id.edt2);

    editText1.setOnEditorActionListener(new EditText.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId,
                KeyEvent event) {
          if (actionId == EditorInfo.IME_ACTION_DONE ||   
                  actionId == EditorInfo.IME_ACTION_NEXT) {
           editText2.requestFocus();
            return false;
          }

            return false;
        }
   });
}

}

0 голосов
/ 04 ноября 2011
 ed1.setOnEditorActionListener(new EditText.OnEditorActionListener() {
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                    // TODO Auto-generated method stub
                     if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_NEXT) {
                        ed1.setNextFocusDownId(R.id.ed2);

                      return false;
                      }
                    return false;
                }
             });

После написания вышеуказанного кода моя проблема решена. Спасибо всем за ответы и поддержку.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...