I have a Listview with EditTexts in every cell. Whenever I add text to the point that the EditText grows 1 line, the ListView scrolls to the top (and usually removes the EditText from view by doing so).
I found a few questions about this but they only seem to have "hacks" as answers and nothing that works for me.
ListView scrolls to top when typing in multi-line EditText
Listview with edittext - auto scroll on "next"
EDIT: After a lot of research, I have found that it is because the editText is resizing, causing the ListView layout its subviews and then resetting to the top. I want to find a way for the EditText to grow while staying at the same place.
I tried this because of a suggestion I found online but, even though it keeps the ListView at the right height, it clears the focus from the EditText and I cannot seem to get it back with requestFocus.
private Stirng getTextWatcher(){
return new TextWatcher(){
@Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override public void onTextChanged(CharSequence s, int start, int before, int count) { }
@Override public void afterTextChanged(Editable s) {
listView.setSelection(index);
}
}
}
So what I would need is either:
Have a way for the
ListViewto not scroll automatically to the top when the subviews are being layed out again orA way to focus my
EditTextafter having calledListView.setSelected()or 3. Have another way to scroll theListViewthat will not clear focus from theEditText.
For option
- I have tried
scrollTo()andsmoothScrollToPosition().scrollTofor some reason works but hides certain items from theListView(they become invisible, not loaded). AndsmoothScrollToPosition()creates an animation where theListViewjumps to the top and then it brings the user back to the Item (and does it 2 or 3 times).