title: Setting the text of TextView as a child of my ListView, affects other child views text
body: <p>I have a <code>ListView</code> in my code which contains <code>TextView</code>s as its child, when my <code>OnItemClickListener</code> is fired I will receive a view. This view is the one that I clicked from the ListView. From this part, I will cast this view to make it as TextView. Next, I will set a text of this TextView. The problem is, when I scroll my ListView upward/downward some of the ListView's child text are also change. the ListView redraw its child containing the text of other child text. How can I fix this?</p>
  
  <p><strong>UPDATE:</strong> The view I recieved on the OnItemClickListener is somehow the same with other child view. I found this out when I tried to compared the previous view I clicked and the newly clicked view by using equals() method. scrolling the listview redraws its child but sometimes there are child view that are the same with other child view those are not visible in the list.</p>
  
  <p>This is my OnItemClickListener</p>
  
  <pre><code>messagesContainer.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
                  if(adapter.getItemViewType(i)==ChatAdapter.VOICE_MESSAGE){
                      RelativeLayout rootView = (RelativeLayout) view;
                      LinearLayout content = (LinearLayout) rootView.getChildAt(0);
                      LinearLayout contentWithBackground = (LinearLayout) content.getChildAt(1);
                      LinearLayout voiceContent = (LinearLayout) contentWithBackground.getChildAt(1);
                      TextView voiceMessage = (TextView) voiceContent.getChildAt(0);
                      voiceMessage.setText("Sample Text");
                  }
              }
          });
  </code></pre>
  
  <p>This my Adapter</p>
  
  <pre><code>public class ChatAdapter extends BaseAdapter {
  
      private List&lt;QBChatMessage&gt; chatMessages;
      private Context context;
      private static final int TXT_MESSAGE = 0;
      private static final int IMAGE_MESSAGE = 1;
      public static final int VOICE_MESSAGE = 2;
      private DisplayImageOptions displayImageOptions;
  
      public ChatAdapter(Context context, List&lt;QBChatMessage&gt; chatMessages){
          this.chatMessages = chatMessages;
          this.context = context;
          initImageLoaderOptions();
      }
  
      public void initImageLoaderOptions() {
          displayImageOptions = new DisplayImageOptions.Builder().showImageOnLoading(R.drawable.ic_stub)
                  .showImageForEmptyUri(R.drawable.ic_empty).showImageOnFail(R.drawable.ic_error).cacheInMemory(true)
                  .cacheOnDisc(true).considerExifParams(true).bitmapConfig(Bitmap.Config.RGB_565).build();
      }
  
      @Override
      public int getViewTypeCount() {
          return 3;
      }
  
      @Override
      public int getItemViewType(int position){
          if(getItem(position).getProperty("fileUID") == null){
              return TXT_MESSAGE;
          } else {
              if (getItem(position).getProperty("type").equals(QBAttachment.PHOTO_TYPE)) {
                  return IMAGE_MESSAGE;
              } else {
                  return VOICE_MESSAGE;
              }
          }
      }
  
      @Override
      public int getCount() {
          if(chatMessages!=null){
              return chatMessages.size();
          } else{
              return 0;
          }
      }
  
      @Override
      public QBChatMessage getItem(int position) {
          if(chatMessages!=null){
              return chatMessages.get(position);
          } else{
              return null;
          }
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          final ViewHolder holder;
          QBChatMessage chatMessage = getItem(position);
          final LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
          int type = getItemViewType(position);
  
          if (convertView == null) {
              if(type == TXT_MESSAGE){
                  convertView = vi.inflate(R.layout.list_item_message, null);
              } else if(type == IMAGE_MESSAGE){
                  convertView = vi.inflate(R.layout.list_item_message_image, null);
              } else{
                  convertView = vi.inflate(R.layout.list_item_message_voice, null);
              }
              holder = createViewHolder(convertView, type, position);
              convertView.setTag(holder);
          } else {
              holder = (ViewHolder) convertView.getTag();
          }
  
          QBUser currentUser = ChatService.getInstance().getCurrentUser();
  
          boolean isOutgoing = chatMessage.getSenderId() != null &amp;&amp; chatMessage.getSenderId().equals(currentUser.getId());
          setAlignment(holder, isOutgoing, type);
  
          if (chatMessage.getProperty("fullName") != null) {
              holder.txtInfo.setText(chatMessage.getProperty("fullName") + ": " + getTimeText(chatMessage));
          } else {
              holder.txtInfo.setText(getTimeText(chatMessage));
          }
  
          if(type == TXT_MESSAGE){
              holder.txtMessage.setText(chatMessage.getBody());
          } else if (type == IMAGE_MESSAGE){
              Log.i("Loading", "Loading");
              ImageLoader.getInstance().displayImage(AttachmentConstants.URL_S3+chatMessage.getProperty("fileUID"), holder.imageMessage, displayImageOptions);
          }
  
          ImageLoader.getInstance().displayImage(AttachmentConstants.URL_FACEBOOK_OPEN+chatMessage.getProperty("social_picture")+ AttachmentConstants.URL_FACEBOOK_CLOSING, holder.socialPhoto, displayImageOptions);
  
          return convertView;
      }
  
      private ViewHolder createViewHolder(View v, int type, final int position) {
          final ViewHolder holder = new ViewHolder();
          holder.content = (LinearLayout) v.findViewById(R.id.content);
          holder.contentWithBG = (LinearLayout) v.findViewById(R.id.contentWithBackground);
          holder.txtInfo = (TextView) v.findViewById(R.id.txtInfo);
          holder.socialPhoto = (ImageView) v.findViewById(R.id.social_photo);
  
          if(type == TXT_MESSAGE){
              holder.txtMessage = (TextView) v.findViewById(R.id.txtMessage);
          } else if(type == IMAGE_MESSAGE) {
              holder.imageMessage = (ImageView) v.findViewById(R.id.imageMessage);
          } else{
              holder.voiceMessage = (TextView) v.findViewById(R.id.voiceMessage);
              holder.voiceSeekBar = (SeekBar) v.findViewById(R.id.voiceSeekBar);
              holder.voiceSeekBar.setEnabled(false);
          }
          return holder;
      }
  
      private String getTimeText(QBChatMessage message) {
          return TimeUtils.millisToLongDHMS(message.getDateSent() * 1000);
      }
  
      private static class ViewHolder {
          public TextView txtMessage;
          public TextView txtInfo;
          public LinearLayout content;
          public LinearLayout contentWithBG;
          public ImageView socialPhoto;
          public ImageView imageMessage;
          public TextView voiceMessage;
          public SeekBar voiceSeekBar;
      }
  }
  </code></pre>
  
  <p>This is list_item_message_voice.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="wrap_content"
      android:layout_height="wrap_content"&gt;
  
      &lt;LinearLayout
          android:id="@+id/content"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentRight="true"
          android:orientation="vertical"
          android:descendantFocusability="blocksDescendants"&gt;
  
          &lt;TextView
              android:id="@+id/txtInfo"
              android:layout_width="wrap_content"
              android:layout_height="20sp"
              android:layout_gravity="right"
              android:textSize="10sp"
              android:textColor="@android:color/secondary_text_dark" /&gt;
  
          &lt;LinearLayout
              android:id="@+id/contentWithBackground"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="right"
              android:background="@drawable/incoming_message_bg"
              android:paddingLeft="10dp"
              android:paddingBottom="10dp"
              android:orientation="horizontal"&gt;
  
              &lt;ImageView
                  android:layout_margin="10dp"
                  android:id="@+id/social_photo"
                  android:layout_width="33.33dp"
                  android:layout_height="33.33dp" /&gt;
  
  
              &lt;LinearLayout
                  android:id="@+id/voiceContent"
                  android:orientation="vertical"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"&gt;
  
                  &lt;TextView
                      android:text="Play"
                      android:id="@+id/voiceMessage"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:textColor="@android:color/black"/&gt;
  
                  &lt;SeekBar
                      android:id="@+id/voiceSeekBar"
                      android:layout_width="100dp"
                      android:layout_height="wrap_content" /&gt;
              &lt;/LinearLayout&gt;
  
  
          &lt;/LinearLayout&gt;
  
      &lt;/LinearLayout&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>