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