Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
269 views
in Technique[技术] by (71.8m points)

android - Unable to reach EditorAction in EditText

I have an EditText in my App where i've set in it's xml android:imeOptions="actionDone" and them in my fragment i'm trying to cast a function which should do stuff on Done click, but instead it has no effect and the softkeyboard doesn't even close.. in bebug the EditorActionListener is not reached when done is pressed...

Which could be the issue of it?

In my fragment the EditorActionListener looks like this:

private lateinit var txtQta: EditText
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        txtQta = view.findViewById(R.id.txtQta)
        txtQta.setOnEditorActionListener { _, i, _ ->
            when(i) {
                EditorInfo.IME_ACTION_DONE -> {
                    addArticolo()
                    true
                }
            else ->
                false
            }
        }
}

my editText:

        <EditText
            android:id="@+id/txtQta"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:autofillHints="qty"
            android:text="@string/_1"
            android:hint="@string/qta"
            android:inputType="number|numberDecimal"
            android:padding="15dp"
            android:selectAllOnFocus="true"
            android:imeOptions="actionDone"
            android:singleLine="true"
            android:textAlignment="center"
            android:textStyle="bold" />

EDIT:

Actually i had another EditorActionListener registered so for that reason it wasn't working..

question from:https://stackoverflow.com/questions/65935633/unable-to-reach-editoraction-in-edittext

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this with input type attribute.

 <androidx.appcompat.widget.AppCompatEditText
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:id="@+id/txtQta"
             android:inputType="text"
             android:imeOptions="actionDone"/>
txtQta.setOnEditorActionListener { _, i, _ ->
    when(i) {
        EditorInfo.IME_ACTION_DONE -> {
            Toast.makeText(requireContext(),"done pressed",Toast.LENGTH_SHORT).show()
            true
        }
        else -> false
    }
}
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...