前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >android RecyclerView 里面嵌套editText,点击RecyclerView内部其他控件让editText失去焦点

android RecyclerView 里面嵌套editText,点击RecyclerView内部其他控件让editText失去焦点

原创
作者头像
用户10521372
修改2023-05-24 17:39:56
1.3K0
修改2023-05-24 17:39:56
举报
文章被收录于专栏:android自用android自用

有很多方法,没详细去尝试,而我的方法是在每个item添加一个hideKeyboard,hideKeyboard是自定义方法,此方法写在activity中

代码语言:java
复制
public void hideKeyboard(View view) {
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

适配器引用的xml的根节点写入android:onClick="hideKeyboard"(如果想要触发onclick最好不要在根节点添加外间距,可以包多一层写内间距)

代码语言:html
复制
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/layout_id"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorWhite"
    android:orientation="vertical"
    android:paddingVertical="@dimen/dp_16"
    android:layout_marginBottom="@dimen/dp_6"
    android:onClick="hideKeyboard">
    
    <EditText
        android:id="@+id/edit_count"
        android:layout_width="@dimen/dp_84"
        android:layout_height="@dimen/dp_35"
        android:layout_marginStart="@dimen/dp_10"
        android:background="@drawable/round_edit_text_gray_bg"
        android:inputType="number"
        android:text="0"
        android:textAlignment="center" />
        
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginStart="@dimen/dp_10"
        android:text="现库存:"
        android:textSize="@dimen/font_small" />
        
    <TextView
        android:id="@+id/current_count"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="10"
        android:textSize="@dimen/font_small" />
    
</LinearLayout>

<font color=red>注意:内部其他控件添加android:clickable="true",父级点击事件会失效</font>

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档