dimanche 19 septembre 2021

How to keep the Done button in the soft_keyboard forever in android?

I am new to android development,
What i am trying to archeive 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?

XML CODE,

    <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"
        />

ANDROID CODE,

    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;
    }
});

output,

enter image description here

enter image description here

I reposting this question as i didn't get answer for my question




Aucun commentaire:

Enregistrer un commentaire