title: Android, Listview on Scroll Item position issue
body: <p>I am facing a problem.
  I am working on QuickBlox Private chat. I want to show date and time with only last message of sent and get. I achieve that but issue is that when ever I scroll that message listview date and time change position and every scroll it shows with other messages not with last. How can I fix that? 
  My BaseAdapter code is below.</p>
  
  <pre><code>public class ChatAdapter extends BaseAdapter {
  
  private final List&lt;QBChatMessage&gt; chatMessages;
  private Activity context;
  private static String inComingMessage = "0";
  private static String outGoingMessage = "0";
  
  public ChatAdapter(Activity context, List&lt;QBChatMessage&gt; chatMessages,
          String inComingMessage, String outGoingMessage) {
      this.context = context;
      this.chatMessages = chatMessages;
      this.inComingMessage = inComingMessage;
      this.outGoingMessage = outGoingMessage;
  }
  
  @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(final int position, View convertView, ViewGroup parent) {
      ViewHolder holder;
      QBChatMessage chatMessage = getItem(position);
      LayoutInflater vi = (LayoutInflater) context
              .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
      if (convertView == null) {
          convertView = vi.inflate(R.layout.list_item_message, null);
          holder = createViewHolder(convertView);
          convertView.setTag(holder);
      } else {
          holder = (ViewHolder) convertView.getTag();
      }
  
      QBUser currentUser = ((ApplicationSingleton) context.getApplication())
              .getCurrentUser();
      boolean isOutgoing = chatMessage.getSenderId() == null
              || chatMessage.getSenderId().equals(currentUser.getId());
      setAlignment(holder, isOutgoing);
      holder.txtMessage.setText(chatMessage.getBody());
      if (chatMessage.getSenderId() != null) {
          if (chatMessage.getSenderId().equals(currentUser.getId())) {
              if (outGoingMessage.equals("1")) {
                  if (chatMessage.isRead()) {
                      holder.txtDateTime
                              .setText("Seen: "
                                      + convertDate(chatMessage.getDateSent() * 1000));
                  } else {
                      holder.txtDateTime.setText(convertDate(chatMessage
                              .getDateSent() * 1000));
                  }
                  outGoingMessage = "0";
              }
          } else {
              if (inComingMessage.equals("1")) {
                  holder.txtDateTime.setText("Seen: "
                          + convertDate(chatMessage.getDateSent() * 1000));
                  inComingMessage = "0";
              }
          }
      } else {
          holder.txtDateTime
                  .setText(convertDate(chatMessage.getDateSent() * 1000));
      }
  
      return convertView;
  }
  
  public void add(QBChatMessage message) {
      chatMessages.add(message);
  }
  
  public void add(List&lt;QBChatMessage&gt; messages) {
      chatMessages.addAll(messages);
  }
  
  private void setAlignment(ViewHolder holder, boolean isOutgoing) {
      if (!isOutgoing) {
          holder.contentWithBG
                  .setBackgroundColor(Color.parseColor("#00aeef"));
  
          LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) holder.contentWithBG
                  .getLayoutParams();
          layoutParams.gravity = Gravity.RIGHT;
          holder.contentWithBG.setLayoutParams(layoutParams);
  
          RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) holder.content
                  .getLayoutParams();
          lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0);
          lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
          holder.content.setLayoutParams(lp);
          layoutParams = (LinearLayout.LayoutParams) holder.txtMessage
                  .getLayoutParams();
          layoutParams.setMargins(0, 10, 20, 0);
          layoutParams.gravity = Gravity.RIGHT;
          holder.txtMessage.setLayoutParams(layoutParams);
  
          layoutParams = (LinearLayout.LayoutParams) holder.txtDateTime
                  .getLayoutParams();
          layoutParams.gravity = Gravity.RIGHT;
          holder.txtDateTime.setLayoutParams(layoutParams);
      } else {
          holder.contentWithBG
                  .setBackgroundColor(Color.parseColor("#F5F5F5"));
  
          LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) holder.contentWithBG
                  .getLayoutParams();
          layoutParams.gravity = Gravity.LEFT;
          holder.contentWithBG.setLayoutParams(layoutParams);
  
          RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) holder.content
                  .getLayoutParams();
          lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0);
          lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
          holder.content.setLayoutParams(lp);
          layoutParams = (LinearLayout.LayoutParams) holder.txtMessage
                  .getLayoutParams();
          layoutParams.setMargins(0, 10, 20, 0);
          layoutParams.gravity = Gravity.LEFT;
          holder.txtMessage.setLayoutParams(layoutParams);
  
          layoutParams = (LinearLayout.LayoutParams) holder.txtDateTime
                  .getLayoutParams();
          layoutParams.gravity = Gravity.LEFT;
          holder.txtDateTime.setLayoutParams(layoutParams);
      }
  }
  
  private ViewHolder createViewHolder(View v) {
      ViewHolder holder = new ViewHolder();
      holder.txtMessage = (TextView) v.findViewById(R.id.txtMessage);
      holder.content = (LinearLayout) v.findViewById(R.id.content);
      holder.contentWithBG = (LinearLayout) v
              .findViewById(R.id.contentWithBackground);
      holder.txtDateTime = (TextView) v.findViewById(R.id.txtDateTime);
      return holder;
  }
  
  public static String convertDate(long dateInMilliseconds) {
      return DateFormat.format("hh:mm", (dateInMilliseconds)).toString();
  }
  
  private static class ViewHolder {
      public TextView txtMessage;
      public TextView txtDateTime;
      public LinearLayout content;
      public LinearLayout contentWithBG;
  }
  }
  </code></pre>