Home > Software engineering >  Can't focus on EditText after setting focus to true
Can't focus on EditText after setting focus to true

Time:03-29

Im having trouble undestanding what is happening here. If I don't mess with "setFocusable" on EditText it works like I excpect (when you click on it the keyboard pops up and you can edit it as normal), if I set it to true it also works like before:

holder.editTextExercise.setFocusable(true);

But if I set it to false, and than back to true, I can no longer see a keyboard pop up, so I can't edit it

    holder.editTextExercise.setFocusable(false);
    holder.editTextExercise.setFocusable(true);

Here is the EditText

<EditText
    android:id="@ id/recyclerExercise"
    android:layout_width="0sp"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:textColor="@color/grey"
    android:backgroundTint="@color/grey"
    android:text="@string/app_name"
    android:textSize="25sp"/>

Im putting different items with EditTexts in the recycler and sometimes I want to change them so they can/can't be editable. What is going on here?

CodePudding user response:

Instead of

holder.editTextExercise.setFocusable(false);
holder.editTextExercise.setFocusable(true);

Try

holder.editTextExercise.setEnabled(false);
holder.editTextExercise.setEnabled(true);
  • Related