2015-09-22 4 views
0

Есть два EditText, и если пользователь вводит четыре символа в первом, фокус автоматически переходит на другой EditText. И когда пользователь вводит первый символ во втором EditText, прокрутка прорывается, и этот второй edittext начинает оставаться за клавиатурой.

Также, когда пользователь фокусируется на втором EditText, он по-прежнему остается за клавиатурой. Если пользователь сначала сфокусируется на первом EditText, тогда закройте клавиатуру и сфокусируйте второй EditText, прокрутка работает идеально.

Эти проблемы возникают только для Samsung Galaxy Grand Prime (версия для Android 4.4.4).
EditText остается за клавиатурой после первого ввода

Вы можете помочь в этом странном поведении?


MyActivity.java

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    //..... 

    txtNewPin.setFocusable(true); 
    txtNewPin2.setFocusable(true); 
    txtNewPin.requestFocus(); 

    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); 

    txtNewPin.addTextChangedListener(getTextChangedListener_txtNewPin()); 
    txtNewPin2.addTextChangedListener(getTextChangedListener_txtNewPin2()); 

    //..... 
} 

private TextWatcher getTextChangedListener_txtNewPin() { 
    return new TextWatcher() { 
     @Override 
     public void beforeTextChanged(CharSequence s, int start, int before, int count) { 

     } 

     @Override 
     public void onTextChanged(CharSequence s, int start, int before, int count) { 
      if (s.length() == 4) { 
       txtNewPin.clearFocus(); 
       txtNewPin2.requestFocus(); 
      } 
     } 

     @Override 
     public void afterTextChanged(Editable editable) { 

     } 
    }; 
} 

private TextWatcher getTextChangedListener_txtNewPin2() { 
    return new TextWatcher() { 
     @Override 
     public void beforeTextChanged(CharSequence s, int start, int before, int count) { 

     } 

     @Override 
     public void onTextChanged(CharSequence s, int start, int before, int count) { 
      if (s.length() == 4) { 
       kart_sifre_degistir_button.performClick(); 
      } 
     } 

     @Override 
     public void afterTextChanged(Editable editable) { 

     } 
    }; 
} 


MyActivity XML

Первый EditText ID: yeni_sifre_bir
Второй EditText ID: yeni_sifre_iki
Третий EditText ID: textview_editText_search (Это отлично работает!)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.xxxx.hce.HCEKartSifreDegistirme"> 

    <RelativeLayout 
     android:id="@+id/creditCardBackground" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     ...> 

     .... 

    </RelativeLayout> 

    <LinearLayout 
     android:id="@+id/sinan1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/creditCardBackground" 
     android:layout_marginTop="10dp" 
     android:background="@color/light_gray" 
     android:descendantFocusability="beforeDescendants" 
     android:focusable="true" 
     android:focusableInTouchMode="true" 
     android:imeOptions="flagNoFullscreen" 
     android:orientation="vertical"> 

     <com.xxxx.yyyyyy.BlackBrandTextview 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dp" 
      android:gravity="center" 
      android:text="4 haneli yeni HCE kart şifrenizi belirleyin" 
      android:textSize="14dp" /> 

     <com.xxxx.yyyyyy.EdittextObject 
      android:id="@+id/yeni_sifre_bir" 
      android:layout_width="240dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_marginTop="5dp" 
      android:background="@drawable/edittext_shape" 
      android:focusable="true" 
      android:focusableInTouchMode="true" 
      android:gravity="center" 
      android:imeOptions="flagNoFullscreen" 
      android:inputType="numberPassword" 
      android:maxLength="4" 
      android:padding="5dp" 
      android:textSize="24dp" /> 

     <com.xxxx.yyyyyy.BlackBrandTextview 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dp" 
      android:gravity="center" 
      android:text="Yeni şifrenizi tekrar giriniz" 
      android:textSize="14dp" /> 

     <com.xxxx.yyyyyy.EdittextObject 
      android:id="@+id/yeni_sifre_iki" 
      android:layout_width="240dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_marginTop="5dp" 
      android:background="@drawable/edittext_shape" 
      android:focusable="true" 
      android:focusableInTouchMode="true" 
      android:gravity="center" 
      android:imeOptions="flagNoFullscreen" 
      android:inputType="numberPassword" 
      android:maxLength="4" 
      android:padding="5dp" 
      android:textSize="24dp" /> 
    </LinearLayout> 

    <EditText 
     android:id="@+id/textview_editText_search" 
     android:layout_width="300dp" 
     android:layout_height="40dp" 
     android:layout_above="@+id/kart_sifre_degistir_button" 
     android:layout_centerVertical="true" 
     android:background="@color/White" 
     android:paddingLeft="10dp" 
     android:textColor="@color/Black" /> 

    <com.xxxx.yyyyyy.ButtonObject 
     android:id="@+id/kart_sifre_degistir_button" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_marginBottom="15dp" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginTop="5dp" 
     android:background="@drawable/button_shape_dijitalkartekle" 
     android:text="Onayla" 
     android:textColor="@color/White" /> 
</RelativeLayout> 


Manifest.xml

<activity 
    android:name="com.xxxxx.yyyyy.MyActivity" 
    android:label="@string/title_activity_hcekart_sifre_degistirme" 
    android:screenOrientation="portrait" > 


я понял, что проблема из-за потери фокуса после полукокса введенного во второй EditText. Он теряет фокус внезапно!

ответ

0

решена. Я изменил расположение MyActivity.xml, как показано ниже (используется Scrollview и RelativeLayout вместо того LinearLayout)

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <RelativeLayout 
      android:id="@+id/creditCardBackground" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      .... > 

      .... 

     </RelativeLayout> 

     <RelativeLayout 
      android:layout_below="@+id/creditCardBackground" 
      android:layout_marginTop="20dp" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@color/..."> 

      <com.xxx.yyy.BlackBrandTextview 
       android:id="@+id/limit_info_text" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:gravity="center_horizontal" 
       android:padding="10dp" 
       android:text="...." 
       android:textColor="@color/..." /> 

      <RelativeLayout 
       android:id="@+id/relative_oran_alt_giris" 
       android:layout_below="@+id/limit_info_text" 
       android:layout_marginLeft="30dp" 
       android:layout_marginRight="30dp" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:visibility="visible" > 

       <com.xxx.yyy.BlackBrandTextview 
        android:id="@+id/tutaroraninfoaltkucuk_oran" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="10dp" 
        android:gravity="center" 
        android:textSize="14dp" 
        android:text="..." /> 

       <com.xxx.yyy.EdittextObject 
        android:id="@+id/yeni_sifre_bir" 
        android:layout_below="@+id/tutaroraninfoaltkucuk_oran" 
        android:layout_width="240dp" 
        android:layout_height="wrap_content" 
        android:background="@drawable/..." 
        android:gravity="center" 
        android:inputType="numberPassword" 
        android:layout_marginTop="5dp" 
        android:maxLength="4" 
        android:padding="5dp" 
        android:textSize="24dp" 
        android:layout_centerHorizontal="true"/> 

       <com.xxx.yyy.BlackBrandTextview 
        android:id="@+id/tutaroraninfoaltkucuk_oran1" 
        android:layout_below="@+id/yeni_sifre_bir" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="10dp" 
        android:gravity="center" 
        android:textSize="14dp" 
        android:text="..." /> 

       <com.xxx.yyy.EdittextObject 
        android:id="@+id/yeni_sifre_iki" 
        android:layout_below="@+id/tutaroraninfoaltkucuk_oran1" 
        android:layout_width="240dp" 
        android:layout_height="wrap_content" 
        android:background="@drawable/..." 
        android:gravity="center" 
        android:inputType="numberPassword" 
        android:layout_marginTop="5dp" 
        android:maxLength="4" 
        android:padding="5dp" 
        android:textSize="24dp" 
        android:layout_alignParentBottom="true" 
        android:layout_centerHorizontal="true"/> 

      </RelativeLayout> 

      <com.xxx.yyy.ButtonObject 
       android:id="@+id/kart_sifre_degistir_button" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="10dp" 
       android:layout_marginRight="10dp" 
       android:layout_marginBottom="10dp" 
       android:layout_marginTop="285dp" 
       android:background="@drawable/...." 
       android:text="Onayla" 
       android:textColor="@color/..." /> 

     </RelativeLayout> 

    </RelativeLayout> 

</ScrollView> 
0

попытка afterTextChanged

private TextWatcher getTextChangedListener_txtNewPin() { 
return new TextWatcher() { 
    @Override 
    public void beforeTextChanged(CharSequence s, int start, int before, int count) { 

    } 

    @Override 
    public void onTextChanged(CharSequence s, int start, int before, int count) { 

    } 

    @Override 
    public void afterTextChanged(Editable editable) { 
     if (editable.length() == 4) { 
      txtNewPin.clearFocus(); 
      txtNewPin2.requestFocus(); 
     } 
    } 
}; 

}

+0

Это не работает. Еще одна идея? – ondermerol

+0

По-моему clearFocus не работает. – ondermerol

+0

, но он работает на моем moto g3 lollipop 5.1.1 – arun

Смежные вопросы