【发布时间】:2016-02-03 18:26:07
【问题描述】:
我在垂直线性布局中几乎没有编辑文本。当处于焦点时,我按下键盘上的下一个按钮,理想情况下焦点应该移动到下一个编辑文本。但是当我将 onClickListener 注册到 edittext 并覆盖 onClick 方法时,我观察到了这一点;按下一个键不会将焦点转移到下一个(或任何其他)编辑文本。
当我没有注册 onClickListener 时,按下下一个按钮时焦点会移动。
你能解释一下为什么会这样吗?有解决办法吗?
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:weightSum="1"
android:focusableInTouchMode="true">
<ScrollView
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/TblLayout">
<TableRow
android:weightSum="10">
<TextView
style="@style/TvTblLabel"
android:text="@string/str1" />
<android.support.design.widget.TextInputLayout
android:id="@+id/il1"
style="@style/IlStyle">
<EditText
android:id="@+id/et1"
style="@style/EditTextNumber"/>
</android.support.design.widget.TextInputLayout>
</TableRow>
<TableRow
android:weightSum="10">
<TextView
style="@style/TvTblLabel"
android:text="@string/str2" />
<android.support.design.widget.TextInputLayout
android:id="@+id/il2"
style="@style/IlStyle">
<EditText
android:id="@+id/et2"
style="@style/EditTextNumber"/>
</android.support.design.widget.TextInputLayout>
</TableRow>
</TableLayout>
</ScrollView>
</LinearLayout>
样式:
<style name="TvTblLabel" parent="@android:style/TextAppearance">
<item name="android:layout_gravity">center_vertical</item>
<item name="android:layout_weight">6.5</item>
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">wrap_content</item>
<!--<item name="android:paddingBottom">3dp</item>-->
<item name="android:paddingRight">3dp</item>
<!-- <item name="android:textSize">20sp</item>-->
<!-- <item name="android:padding">3dip</item>-->
</style>
<style name="IlStyle">
<item name="android:layout_weight">3.5</item>
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="EditTextNumber" parent="@android:style/TextAppearance.Medium">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:inputType">numberDecimal</item>
<item name="android:selectAllOnFocus">true</item>
<item name="android:gravity">right</item>
</style>
片段代码:
private void setup(){
et1.addTextChangedListener(new AppInputWatcher(et1));
et1.setOnClickListener(this);
}
...
@Override
public void onClick(View v) {
EditText et = (EditText)v;
et.setSelection(et.getText().toString().length());
}
...
@Override
public void afterTextChanged(Editable s) {
..
et.removeTextChangedListener(this);
et.setText(setEtStr);
et.setSelection(et.getText().toString().length());
et.addTextChangedListener(this);
}
【问题讨论】:
-
刚刚遇到同样的问题,不敢相信你是唯一遇到类似问题的人。我相信这是一个错误,所以我报告了它:code.google.com/p/android/issues/…
标签: android