CymChad / CymChad/BaseRecyclerViewAdapterHelper

headview 要是有editview 会出现软键盘弹出又消失的情况

Open
#3,326 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Kotlin
Stars
24.6k
Forks
5.2k
PR merge metrics
No merged PRs in 30d

Description

使用的3.0.4版本

问题现象:目前要做一个兑换优惠卷的功能
界面结构:activity中包含一个fragment ,fragment中包含recycleview
1 如果只添加headview 那么 headview中的editview一切正常
2 如果添加headview 同时添加了其他数据 那么点击 editview会看到 软键盘闪一下就消失

目前尝试了
在activitry 添加
android:windowSoftInputMode="stateHidden|adjustPan"
在recycleview中添加
android:descendantFocusability="beforeDescendants"
在editview中点击开启软键盘

以上都未解决问题

部分代码
添加的headview 如下

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/dp_10">

<androidx.appcompat.widget.AppCompatEditText
    android:id="@+id/ed_phone"
    android:layout_width="0dp"
    android:layout_height="@dimen/dp_35"
    android:layout_marginEnd="@dimen/dp_10"
    android:background="@color/white_ffffff"
    android:gravity="center_vertical"
    android:hint="输入兑换码"
    android:maxLength="20"
    android:paddingLeft="@dimen/dp_12"
    android:paddingRight="@dimen/dp_12"
    android:textColor="@color/black3"
    android:textColorHint="@color/black9"
    android:textSize="@dimen/sp_15"
    android:backgroundTint="@color/white_ffffff"
    android:layout_marginStart="@dimen/dp_20"
    android:clickable="true"
    android:focusable="true"
    android:focusableInTouchMode="true"
    app:layout_constraintEnd_toStartOf="@+id/confirm_btn"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    />

<androidx.appcompat.widget.AppCompatButton
    android:id="@+id/confirm_btn"
    android:layout_width="@dimen/dp_55"
    android:layout_height="@dimen/dp_35"
    android:paddingStart="@dimen/dp_10"
    android:paddingEnd="@dimen/dp_10"
    android:paddingTop="@dimen/dp_5"
    android:paddingBottom="@dimen/dp_5"
    android:background="@drawable/all_selector_bt_orange"
    android:gravity="center"
    android:enabled="true"
    android:text="兑换"
    android:textColor="@color/white_ffffff"
    android:textSize="15sp"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/ed_phone"
/>

</androidx.constraintlayout.widget.ConstraintLayout>

val headView = View.inflate(activity, R.layout.item_unuse_coupon_list_item_head, null)

    var btn = headView.findViewById<AppCompatButton>(R.id.confirm_btn)
    btn.setOnClickListener {
        var code =headView.findViewById<AppCompatEditText>(R.id.ed_phone).text
        if(TextUtils.isEmpty(code)){
            activity?.toast("请输入兑换码")
            return@setOnClickListener
        }

        viewModel.exchangeCouponS(code.toString())

    }
    var ediview =   headView.findViewById<AppCompatEditText>(R.id.ed_phone)
    ediview.setOnClickListener{
        context?.let {
            showSoftKeyboard(it,ediview)
        }

    }
    ediview.setOnFocusChangeListener{ v,hasFocus->

        hasFocus
    }

ar adapter = object :
BaseQuickAdapter<GuoGuoCouponBean, BaseViewHolder>(R.layout.item_unuse_coupon_list_item) {
override fun convert(helper: BaseViewHolder, item: GuoGuoCouponBean) {

            if("2" == item.couponType){
                //折扣卷
                var data :String?=null
                (item.rate?:10.00).let {
                    data = DigitalConversionUtils.convertDoubleToString( it)//保留一位有效数字并去掉末尾的0
                }
                data?.let {
                    var dataFormat = String.format(resources.getString(R.string.discount_yang),it) //拼接字符
                    val span: Spannable = SpannableString(dataFormat)
                    //注意这里的span 0.4是缩放比例 一定注意 RelativeSizeSpan 每次都要单独生成
                    span.setSpan( RelativeSizeSpan(0.4f), dataFormat.length-1, dataFormat.length-1, Spannable.SPAN_INCLUSIVE_INCLUSIVE)//(]

// span.setSpan(ForegroundColorSpan(Color.RED), dataFormat.length-1, dataFormat.length-1, Spannable.SPAN_INCLUSIVE_INCLUSIVE)
helper.setText(R.id.discount,span)
}
}else{
var data :String?=null
(item.amount?:0.01).let {
data = DigitalConversionUtils.convertDoubleToString( it)//去掉末尾的0
}
data?.let {
var dataFormat = String.format(resources.getString(R.string.yang_discount),it) //拼接字符
val span: Spannable = SpannableString(dataFormat)
span.setSpan( RelativeSizeSpan(0.4f), 0, 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE)//(]
// span.setSpan( ForegroundColorSpan(Color.RED), 0, 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE)
helper.setText(R.id.discount,span)
}

            }


            helper.setText(R.id.title, item.couponName)
            helper.setText(
                R.id.subtitle,
                TimeFormateUtils.getHomeUpdateTime2(
                    item.startTime?.toLong() ?: 1
                ) + "至" + TimeFormateUtils.getHomeUpdateTime2(
                    item.endTime?.toLong() ?: 1
                )
            )
        }

    }

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the header layout item_unuse_coupon_list_item_head and the code that inflates it, adds it to the RecyclerView adapter, and installs the EditText listeners. Reproduce the issue using the stated structure: the keyboard should remain visible when the header contains list data and ed_phone is tapped. Compare focus and keyboard behavior with and without adapter items to isolate the failing path.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.