I am new to android development ,
What i am trying to achieve is,
When the user clicks the DONE button via the on-screen keyboard(Soft input method) , the existing default editText should turn into a checkBox and also again creating an editText so that the user can enter some data again.
These I can able to do this with creating a button and pressing it but I don't want a button , I want the on-Screen keyboard interactions such as DONE button .
first, i tried it with onKeyListener but it doesn't work on the soft keyboard(mobile phone's) instead it worked on the hardware keyboard such as the laptop keyboard.
and then i can also able to do the above-mentioned function via the On-Screen Keyboard using the onEditerActionListener() , but only once I can do this and after that , the DONE button disappears from the on-Screen keyboard, the ENTER button replaces the DONE button
When for the first i try to enter some data into the editText the DONE button is available and after the ENTER BUTTON replaces it.
1) is there any way to stop the ENTER button from replacing the DONE button on the on_Screen keyboard?
2) OR is there any way to also give the functionality to the enter key also?
<EditText
android:id="@+id/defaultEditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="32dp"
android:inputType="text"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
this.constraintLayout = findViewById(R.id.constraintLayout);
this.defaultEditText = findViewById(R.id.defaultEditText);
defaultEditText.setOnEditorActionListener( new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
//CREATING A CHECKBOX
//CREATIN A EDITTEXT
return true;
}
return false;
}
});
You can use maxLines=1
& imeOptions="actionDone"
to indicate that you don't want to enter
the new line & you're done
. This would always give your expected output.
So your EdiText
would look something like this:
<EditText
android:id="@+id/defaultEditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="32dp"
android:imeOptions="actionDone"
android:inputType="text"
android:maxLines="1"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.