Solution 1 :
Add android:imeOptions="actionDone"
to your EditText in your layout XML.
Problem :
I got a RecyclerView
with multiple EditText
-fields. When I try to edit one of the EditText
-fields and click enter on the virtual keyboard, the focus shifts down to the next EditText
-field, something I don’t want to happen. I want to submit the changes I made in the first EditText
-field and then close the keyboard. I managed to turn off this focus-shifting by adding the following to my .xml file:
android_focusable="true"
android_focusableInTouchMode="true"
But the problem still persists, now the changes just never get submitted as my listener never gets called. If I remove all items except from one in my RecyclerView
everything works like I want. How can I make that happen with more items in myRecyclerView
too?
My bind
function inside my UserCardItem.kt
file;
override fun bind(viewHolder: ViewHolder, position: Int) {
...
viewHolder.itemView.creditcard_nickname.setOnEditorActionListener{ _, actionId, _ ->
if(actionId == EditorInfo.IME_ACTION_DONE){
saveNickname(viewHolder)
true
} else {
false
}
}
private fun saveNickname(viewHolder : ViewHolder){
val nickname = viewHolder.itemView.creditcard_nickname.text.toString()
userCreditcard.nickname = nickname
UserCardStore().updateNickname(userCreditcard)
}
Comments
Comment posted by Muddassir Ahmed
Can you please add the code of your listener and the code related to your submit functionality?
Comment posted by sveggen
@MuddassirAhmed I have added the code related now. Thank you for showing interest
Comment posted by Muddassir Ahmed
Can you try adding this to your EditText?
Comment posted by Muddassir Ahmed
Cool. Can you accept my answer?
Comment posted by stackoverflow.com/questions/41790357/…
Not sure. You can do that through some code though.