删除EditText自动对焦到邻居EditText

时间:2017-07-16 10:47:24

标签: android android-layout

我在同一个布局中有2个edittext,我希望在编辑其中一个时不会在另一个edittext上自动跳转。我尝试了一切!帮助

这个文字需要填写textarea .................................... XML:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="50dp"
        android:layout_marginTop="20dp"
        android:orientation="horizontal"
        android:focusable="true"
        android:focusableInTouchMode="true">

        <EditText
            android:id="@+id/editText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="Axis name"
            android:inputType="textPersonName"
            android:text="@string/NomeAsse"
            android:textAlignment="center"
            android:textSize="20dp"
            android:cursorVisible="false"/>

        <EditText
            android:id="@+id/editText2"
            android:layout_width="206dp"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="multiplier"
            android:inputType="numberDecimal"
            android:text="@string/ValoreAsse"
            android:cursorVisible="false"/>

        <TextView
            android:id="@+id/nm"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_weight="0.5"
            android:text="---"
            android:textAlignment="center"
            android:textSize="23dp" />

        <TextView
            android:id="@+id/kgm"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_weight="0.5"
            android:text="---"
            android:textAlignment="center"
            android:textSize="23dp" />

    </LinearLayout>

2 个答案:

答案 0 :(得分:0)

android没有任何简单的方法可以跳转到EditTexts,你必须使用addTextChangedListener并检查长度并跳转到其他程序

例如:

editTextOne.addTextChangedListener(new TextWatcher() {

   public void afterTextChanged(Editable s) {}

   public void beforeTextChanged(CharSequence s, int start,
     int count, int after) {
         if(s.length >4) // focuse to another editText
   }

   public void onTextChanged(CharSequence s, int start,
     int before, int count) {
   }
  });

答案 1 :(得分:0)

我以这种方式解决。

主要活动 - &gt; onCreate() - &gt;

k.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if(i== EditorInfo.IME_ACTION_DONE){ //Clear focus here from edittext k.clearFocus(); InputMethodManager imm = (InputMethodManager) rootView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(rootView.getWindowToken(), 0); return true; } return false; } });

其中k是EditText。