0

I am trying to create a list with recyclerview (picture below), and inside i have an edittext, textview and those views can be change.

enter image description here

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.

1 Answers1

0

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);
       }
});
Jyoti JK
  • 2,141
  • 1
  • 17
  • 40