Клавиатура перезагружается после каждого ввода

Пока считаю, что это как-то связано с классом TextWatcher.

Всякий раз, когда я начинаю печатать в поле EditText, клавиатура просто перезагружается.

Если я хочу ввести слово целиком заглавными буквами, мне нужно снова и снова нажимать заглавные буквы после ввода каждого слова. То же самое и с цифрами: когда я переключаюсь на цифровой ввод после нажатия любой цифры, клавиатура возвращается к обычной клавиатуре qwerty.

Я хочу, чтобы клавиатура была последовательной при наборе текста.

Любая помощь приветствуется.

Ниже мой TextWatcher класс.

public class MyTextWatcher implements TextWatcher {
    private static final String TAG = "MyTextWatcher";
    private View view;
    EditText qtyView;

    public MyTextWatcher(View view) {
        this.view = view;
    }

    @Override
    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        Log.d(TAG, "beforeTextChanged: " + "before");

    }

    @Override
    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        Log.d(TAG, "onTextChanged: " + "onTextChanged");

    }

    public void afterTextChanged(Editable s) {
        String qtyString = s.toString().trim();

        qtyView = (EditText) view.findViewById(R.id.edtFillupDetails);
        ListViemItems listItems = (ListViemItems) qtyView.getTag();

        if (!listItems.getEditTextVal().equals(qtyString)) {

            listItems.setEditTextVal(qtyString);
            if (!listItems.getEditTextVal().equals("")) {

                int position = qtyView.getSelectionStart();
                qtyView.setText(listItems.getEditTextVal());

                qtyView.setSelection(qtyString.toString().trim().length());

            } else {
                qtyView.setText("");
            }
        }

        return;
    } 
}

Мой XML-файл

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="7dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="4"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/txtFillupDetails"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1.5"
            android:gravity="start|center"
            android:textColor="#333"
            android:textSize="16dp" />

        <EditText
            android:id="@+id/edtFillupDetails"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2.5"
            android:background="@drawable/edit_text_croner"
            android:clickable="true"
            android:padding="@dimen/registrnpadding"
            android:shadowRadius="2" />

    </LinearLayout>
</LinearLayout>

И мой файл манифеста

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.lunetta.etro.e_tro">

    <!-- To auto-complete the email text field in the login form with the user's emails -->
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />  

    <application
        android:allowBackup="true"
        android:icon="@drawable/logo1"
        android:label="@string/app_name"
        android:roundIcon="@drawable/logo1"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar"
            android:windowSoftInputMode="adjustResize|stateHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".Fillup_Details"
            android:label="Pre-Departure Details"
            android:windowSoftInputMode="adjustPan">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>       
    </application>

</manifest>


person An08NY    schedule 14.10.2017    source источник
comment
выглядит нормально для меня. Использовали ли вы фокусируемый и тип ввода в файле макета ??   -  person Akhilesh Awasthi    schedule 14.10.2017
comment
Я пробовал обе вещи в файле макета, но они не влияют на это.   -  person An08NY    schedule 14.10.2017
comment
Хорошо. Используйте editText.requestFocus() в afterTextChanged TextWatcher. Это грязно, но может просто работать для вас.   -  person Akhilesh Awasthi    schedule 14.10.2017
comment
нет, это не так.   -  person An08NY    schedule 14.10.2017
comment
Вы можете опубликовать свой макет xml и манифест здесь.   -  person Akhilesh Awasthi    schedule 14.10.2017
comment
да, отредактировал вопрос   -  person An08NY    schedule 14.10.2017
comment
Наблюдатель за текстом находится внутри MainActivity ??   -  person Akhilesh Awasthi    schedule 14.10.2017
comment
нет, TextWatcher вызывается в классе ListAdapter MainActivity.   -  person An08NY    schedule 14.10.2017
comment
Удалите stateHidden из манифеста android:windowSoftInputMode=adjustResize|stateHidden и добавьте android:focusable =true и android:inputType=text внутри ur EditText   -  person Akhilesh Awasthi    schedule 14.10.2017
comment
хорошо, я сказал это неправильно, MainActivity, которую вы спросили, не та. TextWatcher применяется для действия Fillup_Details.   -  person An08NY    schedule 14.10.2017
comment
попробуйте две другие вещи.   -  person Akhilesh Awasthi    schedule 14.10.2017
comment
Однако android:focusable =true и android:inputType=text не работают.   -  person An08NY    schedule 14.10.2017


Ответы (1)


Нашел решение в другой теме:

edittext.settext() изменяет клавиатуру введите значение по умолчанию [от ?123 до ABC]

Проблема в editText.setText(text) части кода, которая обновляет клавиатуру. Чтобы исправить это, попробуйте следующее:

editText.getText().clear()
editText.append(text)

Надеюсь кому поможет!)

person Sergey Domashchuk    schedule 02.08.2021