title: Saving EditText content in RecyclerView
body: <p>I have list item with <code>EditText</code> in it, I don't know how many items there will be.
  I have a problem when I enter some text in <code>EditText</code>, and then scroll down a <code>RecyclerView</code>, after I've scroll up again there is no text in my first <code>EditText</code>.</p>
  
  <p>I am wondering what, and where should I write code so that while the user is typing or finished typing (I was thinking to do that with a <code>TextWatcher</code>) in the <code>EditText</code> the text gets saved into into a file (I'll save it in a .txt file in the external storage) </p>
  
  <p>Am I supposed to do so in the <code>onCreate</code> method of the activity or in the adapter class or elsewhere? </p>
  
  <p>Here is some code</p>
  
  <h2>Main Activity code</h2>
  
  <pre><code> public class MainActivity extends Activity {
  
      RecyclerView mRecyclerView;
      MyAdapter mAdapter;
      String[] mDataSet= new String[20];
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // generating text for editText Views
          for (int i = 0; i&lt;=19; i++){
          mDataSet[i]= "EditText n: "+i;
  
      }
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
          mAdapter = new MyAdapter(mDataSet);
          mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
          mRecyclerView.setItemAnimator(new DefaultItemAnimator());
          mRecyclerView.setAdapter(mAdapter);
          mRecyclerView.setHasFixedSize(true);
      }
  </code></pre>
  
  <h2>My adapter code</h2>
  
  <pre><code>public class MyAdapter extends RecyclerView.Adapter&lt;MyAdapter.ViewHolder&gt; {
  
  private String[] mDataset;
  
  
  public static class ViewHolder extends RecyclerView.ViewHolder {
      // each data item is just a string in this case
      public EditText mEditText;
  
      public ViewHolder(View v) {
          super(v);
  
          mEditText = (EditText) v.findViewById(R.id.list_item_edittext);
      }
  }
  
  public MyAdapter(String[] myDataset) {
      mDataset = myDataset;
  }
  
  @Override
  public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
                                                   int viewType) {
  
      View v = LayoutInflater.from(parent.getContext())
              .inflate(R.layout.list_item, parent, false);
  
      ViewHolder vh = new ViewHolder(v);
      return vh;
  }
  
  @Override
  public void onBindViewHolder(ViewHolder holder,  final int position) {
      holder.mEditText.setText(mDataset[position]);
  
      //without this addtextChangedListener my code works fine ovbiusly
      // not saving the content of the edit Text when scrolled
      // If i add this code then when i scroll all textView that go of screen
      // and than come back in have messed up content
      holder.mEditText.addTextChangedListener(new TextWatcher() {
  
          @Override
          public void onTextChanged(CharSequence s, int start,
                                    int before, int count) {
             //setting data to array, when changed
             // this is a semplified example in the actual app i save the text
             // in  a .txt in the external storage
             mDataset[position] = s.toString();
          }
  
          @Override
          public void beforeTextChanged(CharSequence s, int start,
                                        int count, int after) {
  
          }
  
          @Override
          public void afterTextChanged(Editable s) {
  
          }
      });
  
  }
  
  @Override
  public int getItemCount() {
      return mDataset.length;
  }
  </code></pre>
  
  <p>without this "addtextChangedListener" my code works fine obviusly not saving the content of the edit Text when scrolled. If i add this code,  when i scroll all editText views that go off screen and than come back in have messed up content.</p>