/ Android

监听EditText中的确定事件

布局文件

<EditText
        android:paddingLeft="12dp"
        android:paddingRight="12dp"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:background="@color/white"
        android:maxLines="1"
        app:layout_constraintBottom_toBottomOf="parent"
        onEditorActionListener="@{viewModel.editorActionEvent}"
        android:imeActionLabel="@string/confirm"
        android:imeOptions="actionDone"
        android:inputType="text"
        />

绑定事件

package com.sunmoon.mingshuo.viewModel

import android.app.Application
import android.view.KeyEvent
import android.widget.TextView
import com.sunmoon.mingshuo.spider.Spider
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import me.goldze.mvvmhabit.base.BaseViewModel

class FictionViewModel(application: Application) : BaseViewModel(application) {
  
  var editorActionEvent = TextView.OnEditorActionListener { v, actionId, event ->
      if(actionId == EditorInfo.IME_ACTION_DONE) {
          // do something
      }
      true
  }
}
监听EditText中的确定事件
分享