title: addTextChangedListener() fired multiple times and for all edittext fields in listview
body: <p>I have a listview with 4 list item each containing 2 text views and 1 edittext view. I have defined a addTextChangedListener in the custom adapter to lookout for changes in edittext and then save the text.</p>
  
  <p>The addTextChangedListener is firing once when text in edittext view in list item 2,3 and 4 is changed but it fires multiple times when edit text in list item 1 is clicked. Also when I print the position of list item clicked from base adapter it shows that all 4 list items are looped through.</p>
  
  <p>Could someone please explain why this is happening and suggest a solution please.</p>
  
  <p>Below is the code and logcat output.</p>
  
  <p>List View XML :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context="com.dumbrella.uidesign.ListView"&gt;
  
  
  &lt;ListView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/listView"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="20dp"
      android:descendantFocusability="beforeDescendants" /&gt;
  
  &lt;Button
      style="?android:attr/buttonStyleSmall"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Submit"
      android:id="@+id/btnSubmit"
      android:layout_below="@+id/listView"
      android:layout_centerHorizontal="true" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>List Item XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="?android:attr/listPreferredItemHeight"&gt;
  
  &lt;TextView
      android:layout_width="wrap_content"
      android:layout_height="match_parent"
      android:textAppearance="?android:attr/textAppearanceLarge"
      android:textSize="32dp"
      android:text="IC"
      android:gravity="center"
      android:id="@+id/questionIcon"
      android:layout_alignParentLeft="true"
      android:layout_alignParentStart="true"
      android:layout_alignParentBottom="true"
      android:layout_alignParentTop="true" /&gt;
  
  &lt;TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textAppearance="?android:attr/textAppearanceSmall"
      android:text="Small Text"
      android:id="@+id/questionText"
      android:layout_alignParentRight="true"
      android:layout_alignParentEnd="true"
      android:layout_toRightOf="@+id/questionIcon"
      android:layout_toEndOf="@+id/questionIcon"
      android:layout_alignParentTop="true" /&gt;
  
  &lt;EditText
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/userAnswer"
      android:layout_alignParentBottom="true"
      android:layout_toRightOf="@+id/questionIcon"
      android:layout_alignRight="@+id/questionText"
      android:layout_alignEnd="@+id/questionText"
      android:inputType="text"
      android:textSize="12dp"/&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>List View Activity :</p>
  
  <pre><code>import android.content.Context;
  import android.content.SharedPreferences;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.text.Editable;
  import android.text.TextWatcher;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.AdapterView;
  import android.widget.BaseAdapter;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.ListView;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import java.util.ArrayList;
  
  public class QuestionsListView extends AppCompatActivity {
  
  String TAG = "Question List View Activity";
  
  ArrayList&lt;ListData&gt; adapterList = new ArrayList&lt;ListData&gt;();
  ListView listViewDetail;
  QuestionsAdapter mQuestionAdapter;
  SharedPreferences userAnswersSharedPreferences;
  SharedPreferences.Editor userAnswersSharedPreferencesEditor;
  
  private String[] questionIcon = new String[]{
          "T", "W", "M", "C"
  };
  
  private String[] questionDescription = new String[]{
          "Question1?", "Question2?", "Question3?", "Question4?"
  };
  
  private String[] userAnswerHint = new String[]{
          "Answer1", "Answer2", "Answer3", "Answer4"
  };
  
  private String[] userAnswers = new String[] {
          "Null", "Null", "Null", "Null"
  };
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_list_view);
  
      listViewDetail = (ListView) findViewById(R.id.listView);
  
      getDataInList();
      mQuestionAdapter = new QuestionsAdapter();
      listViewDetail.setAdapter(mQuestionAdapter);
  
      userAnswersSharedPreferences = getSharedPreferences("UserAnswersPreferences", Context.MODE_PRIVATE);
      userAnswersSharedPreferencesEditor = userAnswersSharedPreferences.edit();
  
      Button btnSubmit = (Button) findViewById(R.id.btnSubmit);
      btnSubmit.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              for (int i=0; i&lt;questionIcon.length; i++) {
  
                  ListData currentListData1 = mQuestionAdapter.getItem(i);
                  Log.v("TAG" , currentListData1.getQuestionIcon());
                  Log.v("TAG" , currentListData1.getQuestionDescription());
                  Log.v("TAG" , currentListData1.getUserAnswerHint());
                  Log.v("TAG" , currentListData1.getUserAnswer());
              }
          }
      });
  }
  
  private void getDataInList() {
      for (int i = 0; i &lt; questionIcon.length; i++) {
          // Create a new object for each list item
          ListData listData = new ListData();
          listData.setQuestionIcon(questionIcon[i]);
          listData.setQuestionDescription(questionDescription[i]);
          listData.setUserAnswerHint(userAnswerHint[i]);
          listData.setUserAnswer("Null");
          // Add this object into the ArrayList myList
          adapterList.add(listData);
      }
  }
  
  public class QuestionsAdapter extends BaseAdapter {
  
      @Override
      public int getCount() {
          return adapterList.size();
      }
  
      @Override
      public ListData getItem(int position) {
          return adapterList.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          return 0;
      }
  
      @Override
      public View getView(final int position, View convertView, ViewGroup parent) {
  
          if (convertView == null) {
  
              LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              convertView = inflater.inflate(R.layout.list_item, parent, false);
          }
  
          final TextView questionText = (TextView) convertView.findViewById(R.id.questionText);
          final TextView questionIcon = (TextView) convertView.findViewById(R.id.questionIcon);
          final EditText userAnswer = (EditText) convertView.findViewById(R.id.userAnswer);
  
          final ListData currentListData = getItem(position);
  
          questionIcon.setText(currentListData.getQuestionIcon());
          questionText.setText(currentListData.getQuestionDescription());
          //userAnswer.setHint(currentListData.getUserAnswerHint());
  
          questionIcon.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  Log.v("TAG", "In Listener");
                  questionIcon.setText("Z");
              }
          });
  
          userAnswer.addTextChangedListener(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) {
                  Log.v("ListView Adapter After", "Text Changed to :" + s.toString());
                  Log.v("ListView Adapter After", "List Item Clicked :" + String.valueOf(position));
                  currentListData.setUserAnswer(userAnswer.getText().toString());
                  switch (position) {
                      case 0:
                          userAnswersSharedPreferencesEditor.putString("T",s.toString());
                          break;
                      case 1:
                          userAnswersSharedPreferencesEditor.putString("W",s.toString());
                          break;
                      case 2:
                          userAnswersSharedPreferencesEditor.putString("M",s.toString());
                          break;
                      case 3:
                          userAnswersSharedPreferencesEditor.putString("C",s.toString());
                          break;
                  }
                  userAnswersSharedPreferencesEditor.commit();
                  userAnswers[position] = currentListData.getUserAnswer();
              }
          });
  
          return convertView;
      }
  }
  
  private class ListData {
  
      private String questionIcon;
      private String questionDescription;
      private String userAnswerHint;
      private String userAnswer;
  
      public String getQuestionIcon() {
          return questionIcon;
      }
  
      public void setQuestionIcon(String questionIcon) {
          this.questionIcon = questionIcon;
      }
  
      public String getQuestionDescription() {
          return questionDescription;
      }
  
      public void setQuestionDescription(String questionDescription) {
          this.questionDescription = questionDescription;
      }
  
      public String getUserAnswerHint() {
          return userAnswerHint;
      }
  
      public void setUserAnswerHint(String userAnswerHint) {
          this.userAnswerHint = userAnswerHint;
      }
  
      public String getUserAnswer() {
          return userAnswer;
      }
  
      public void setUserAnswer(String userAnswer) {
          this.userAnswer = userAnswer;
      }
  }
  }
  </code></pre>
  
  <p>Logcat Output : (when text in list items 2,3 and 4 is changed)</p>
  
  <pre><code>05-11 20:58:03.453 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: Text Changed to :f
  05-11 20:58:03.453 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: List Item Clicked :2 
  
  
  05-11 20:58:03.453 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: Text Changed to :f
  05-11 20:58:03.453 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: List Item Clicked :3
  </code></pre>
  
  <p>05-11 20:58:03.453 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: Text Changed to :f
     05-11 20:58:03.453 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: List Item Clicked :4</p>
  
  <p>Logcat Output : (when text in list item 1 is changed)</p>
  
  <pre><code>05-11 20:59:22.928 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: Text Changed to :f
  05-11 20:59:22.928 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: List Item Clicked :0
  05-11 20:59:22.929 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: Text Changed to :f
  05-11 20:59:22.929 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: List Item Clicked :1
  05-11 20:59:22.929 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: Text Changed to :f
  05-11 20:59:22.929 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: List Item Clicked :2
  05-11 20:59:22.929 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: Text Changed to :f
  05-11 20:59:22.929 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: List Item Clicked :3
  05-11 20:59:22.929 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: Text Changed to :f
  05-11 20:59:22.929 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: List Item Clicked :0
  05-11 20:59:22.929 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: Text Changed to :f
  05-11 20:59:22.929 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: List Item Clicked :1
  05-11 20:59:22.929 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: Text Changed to :f
  05-11 20:59:22.929 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: List Item Clicked :2
  05-11 20:59:22.929 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: Text Changed to :f
  05-11 20:59:22.929 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: List Item Clicked :3
  05-11 20:59:22.929 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: Text Changed to :f
  05-11 20:59:22.929 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: List Item Clicked :0
  05-11 20:59:22.929 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: Text Changed to :f
  05-11 20:59:22.929 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: List Item Clicked :1
  05-11 20:59:22.929 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: Text Changed to :f
  05-11 20:59:22.929 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: List Item Clicked :2
   05-11 20:59:22.930 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: Text Changed to :f
   05-11 20:59:22.930 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: List Item Clicked :3
   05-11 20:59:22.930 3914-3914/com.dumbrella.uidesign 
  V/ListView Adapter After: Text Changed to :f
   05-11 20:59:22.930 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: List Item Clicked :0
   05-11 20:59:22.930 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: Text Changed to :f
   05-11 20:59:22.930 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: List Item Clicked :1
   05-11 20:59:22.930 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: Text Changed to :f
  05-11 20:59:22.930 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: List Item Clicked :2
   05-11 20:59:22.930 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: Text Changed to :f
   05-11 20:59:22.930 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: List Item Clicked :3
    05-11 20:59:22.930 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: Text Changed to :f
    05-11 20:59:22.930 3914-3914/com.dumbrella.uidesign V/ListView Adapter After: List Item Clicked :0
  </code></pre>