Вопрос

I've got a number picker in my activity. It's possible for the user to do a text selection on the current number. The problem is I'd like to reset the selection when the orientation change to avoid the change of the action bar. As extreme solution I could disable selection but I don't know how. I tried to call clearFocus, I tried to set empty longClikListner, I tried to set setSelected(false) and so on. How can I reset a text selection?

Это было полезно?

Решение 2

I post the solution after a lot of work :) Use a dummy layout element with focus, clear the focus from the number picker and request the focus from your dummy element, but you have to do this in onResume and onPause.

Другие советы

Supposing the field is an EditText:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    text.setSelection(0, 0);
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top