I have chat view, that have scroll view, that contanins textviews, and edit text above the scroll view. When new message print into textview, scroll view fullscrolling to end.
activity.scrollView.post(new Runnable() {
@Override
public void run() {
activity.scrollView.fullScroll(ScrollView.FOCUS_DOWN);
}
});
But if I typed text into EditText, it's always scrolling down and lose focus from edit text (so if messages printed often, it's unreal to type message). How can I fix it? I found in stack some answer, but it didn't help me. Here is it.
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (hasFocus) {
scrollView.postDelayed(new Runnable() {
@Override
public void run() {
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
}
}, 200);
} else {
}
}
});
UPD: My textviews, that are child of scrollview, had property
textView.setTextIsSelectable(true);
I removed that property, and now it's OK, I can type message and autoscrolling does not prevent me. But it still question why that happened. Also I still would like the ability to select(copy) text.
You can add a request for focus after the scroll event. You may need to wrap it in a runnable to wait for the scroll to finish, something like this:
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
scrollView.post(new Runnable() {
@Override
public void run() {
editText.requestFocus();
}
});
See this post for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With