I'm trying to enable my users to rename a file using the app, my problem is more about the design. I want that when renaming, the EditText will include the old name, and it will be selected, not including the file extension.
I've managed to do that but my problem is that even though the text is selected, the keyboard, and the cursor on the text, are not showing. This makes the user click on the editText to rename it, which cancels the selection, so this is why it really bothers me.
Image for reference:
My EditText xml (ignore the visibility attribute):
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/renameEditText"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:layout_marginBottom="8dp"
android:paddingLeft="20dp"
android:visibility="gone"
android:focusable="true"/>
My Code for setting selection:
renameEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
String text = renameEdit.getText().toString();
if (!text.isEmpty()) {
int index = text.lastIndexOf('.');
if (index == -1)
renameEdit.selectAll();
else
renameEdit.setSelection(0, index);
}
}
}
});
Any advices?