我有两个编辑文本在同一个布局,我希望在两个编辑之一被编辑时,不会自动跳转到其他编辑文本。我什么都试过了!救命啊。
本文本须填写文本区域.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>
发布于 2017-07-16 03:12:52
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) {
}
});
发布于 2017-07-16 03:33:33
我就是这样决定的。
主要活动-> onCreate() ->
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。
https://stackoverflow.com/questions/45127663
复制