'How to prevent recyclerView from resetting edittext when scrolling?
I am trying to create a list with recyclerview (picture below), and inside i have an edittext, textview and those views can be change.
However the value inside edittext and textview are being resetted if the Recyclerview decide to reinflat it, what i want to know is how does one stop Recyclerview from doing so ? I've googled it for a while, i've tried to Override getItemViewType and still no luck.
Solution 1:[1]
Try this method,
1.Use a list which will have edittext value of items. //edittextlist
HashMap<Integer,String> edittextlist=new HashMap<>();
If you want to store it permanantly, then use SharedPref.
2.Choose item's data which will be unique //position
3.Set edittext value based on the edittextlist.
if(edittextlist.get(position)!=null) {
holder.edittext.setText(edittextlist.get(position));
}
else {
holder.edittext.setText("");
}
4. Add listener to your edittext,
holder.edittext.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void afterTextChanged(Editable s) {
edittextlist.put(position,s.toString);
}
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |

