android - 键盘打开后更改 EditText 焦点
问题描述
当我点击它时,我注意到了 EditText 焦点的问题。通常,我有带有 RecyclerView 的 NestedScroll,其中有一些 EditText 控件。在点击其中一个后显示键盘,但之后我的焦点设置为从顶部开始的第一个 EditTest,而不是我点击的那个。
你有什么建议我该如何解决这个问题?
下面我放了我的活动布局的例子。
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="@dimen/general_padding"
android:background="@color/window_color">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:orientation="vertical">
<LinearLayout
android:id="@+id/genericSection"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Title -->
<LinearLayout
android:id="@+id/titleContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/item_formt_element_title" />
<include layout="@layout/item_formt_element_single_separator" />
</LinearLayout>
<!-- Tags -->
<LinearLayout
android:id="@+id/tagsContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/item_formt_element_tags" />
<include layout="@layout/item_formt_element_single_separator" />
</LinearLayout>
</LinearLayout>
<!-- Form elements -->
<android.support.v7.widget.RecyclerView
android:id="@+id/formRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
app:layout_constraintTop_toBottomOf="@id/genericSection"/>
<!-- Footer -->
<View
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="@drawable/rounded_bottom"
android:layout_marginBottom="@dimen/general_padding_bottom"
app:layout_constraintStart_toStartOf="@id/formtsRecyclerView"
app:layout_constraintEnd_toEndOf="@id/formtsRecyclerView"
app:layout_constraintTop_toBottomOf="@id/formtsRecyclerView"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
解决方案
你还没有共享代码。您是否尝试过在 onClick 方法中使用请求焦点?
public void onClick(View v) {
EditText ed = v.findViewById(R.id.yourEditText);
ed.requestFocus();
}
推荐阅读
- android - 我正在尝试从数组列表中的房间数据库中获取数据,但它仅显示 android 中的最后一条记录
- ruby-on-rails - 无法从我的 Windows 桌面访问在 AWS Ubuntu 上运行的 rails localhost
- arrays - 用汇编语言 x86 从大到小对数组进行排序
- amazon-iam - 使用 nodejs aws sdk 连接到 aws 弹性搜索
- sql - 如何从jsonb int数组制作sql表列
- angular - 每次将新对象推入数组时,模板中的循环都会重复。我怎样才能在模板中处理这个?
- c# - 在 Tableview 中排序
- javascript - Vue.js 嵌套引用,方法未定义
- kubernetes - OpenShift 模板“对象已存在”错误
- html - 以角度在 mat-card 上使用阴影