Parcourir la source

1.设置edittext获取焦点不弹软键盘

王鹏鹏 il y a 2 ans
Parent
commit
17c060b754

+ 20 - 6
mmse/src/main/java/com/yingyangfly/mmse/adapter/SelectedItemAdapter.kt

@@ -2,9 +2,12 @@ package com.yingyangfly.mmse.adapter
 
 import android.annotation.SuppressLint
 import android.text.TextUtils
+import android.view.MotionEvent
 import com.yingyang.mmse.R
 import com.yingyang.mmse.databinding.ItemSelectedItemBinding
 import com.yingyangfly.baselib.adapter.BaseDataBindingAdapter
+import com.yingyangfly.baselib.ext.getEndAnimation
+import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.baselib.ext.setOnSingleClickListener
 import com.yingyangfly.baselib.ext.setTextColorResource
 
@@ -18,7 +21,7 @@ class SelectedItemAdapter(override val layoutId: Int = R.layout.item_selected_it
 
     var onSelectedItemClickListener: ((bean: String) -> Unit)? = null
 
-    @SuppressLint("NotifyDataSetChanged")
+    @SuppressLint("NotifyDataSetChanged", "ClickableViewAccessibility")
     override fun onBindViewHolder(binding: ItemSelectedItemBinding, item: String, position: Int) {
         binding.data = item
         if (TextUtils.equals(selectedData, item)) {
@@ -28,11 +31,22 @@ class SelectedItemAdapter(override val layoutId: Int = R.layout.item_selected_it
             binding.tvNumber.setBackgroundResource(R.drawable.bg_unselected_item)
             binding.tvNumber.setTextColorResource(R.color.color_FF222222)
         }
-        binding.selectedLayout.setOnSingleClickListener {
-            selectedData = item
-            notifyDataSetChanged()
-            onSelectedItemClickListener?.invoke(item)
+        binding.selectedLayout.setOnTouchListener { v, event ->
+            when (event.action) {
+                MotionEvent.ACTION_DOWN -> {
+                    v.startAnimation(getScaleAnimation())
+                }
+                MotionEvent.ACTION_UP -> {
+                    v.startAnimation(getEndAnimation())
+                    selectedData = item
+                    notifyDataSetChanged()
+                    onSelectedItemClickListener?.invoke(item)
+                }
+                MotionEvent.ACTION_CANCEL -> {
+                    v.startAnimation(getEndAnimation())
+                }
+            }
+            true
         }
-
     }
 }