NotifyDatasetChanged() of BaseAdpater adds a new row if used to update already added element in the list
<p>I have a list view and a BaseAdapter. I use add an element to list(its dataset which is an arraylist) and call notifydatasetchanged(). It works great. But if I want to update an already added element, I extract that element from dataset and update its content as I want and then again call notifydatasetChanged(). But now it adds one more row in the list same as my updated one.. :( Any help will be appreciated.
Thanks.</p>

<p><strong>Update:</strong> I have a message list. When I send the message, I add a message in the list with its progress bar ON. In background, a thread runs which sends the message to server. On return of the thread, I want to hide that progress bar from the view I added as a message in the list. The message pojo has a boolean property which says a message is pending to send or not. and depending on it show/hide progress bar in getView().</p>

<p>Here is my code: 
<strong>Adapter:</strong> </p>

<pre><code>public class MessagesAdapter extends BaseAdapter {
private ArrayList&lt;Messages&gt; messages=new ArrayList&lt;Messages&gt;();
private LayoutInflater inflater;
private Context mContext;
private static MessagesAdapter instance=null;
private boolean init=false;
public static MessagesAdapter getInstance() {
    if(instance==null){
        instance=new MessagesAdapter();
    }
    return instance;
}
public void init(Context context, ArrayList&lt;Messages&gt; arrayList) {
    this.mContext=context;
    this.messages=arrayList;
    inflater=LayoutInflater.from(this.mContext);
    init=true;
}
@Override
public int getCount() {
    // TODO Auto-generated method stub
    return messages.size();
}

@Override
public Object getItem(int arg0) {
    // TODO Auto-generated method stub
    return messages.get(arg0);
}

@Override
public long getItemId(int arg0) {
    // TODO Auto-generated method stub
    return arg0;
}
public void addMessage(Messages message){
    this.messages.add(message);
    notifyDataSetChanged();

}
@Override
public View getView(int position, View convertView, ViewGroup list) {
    View view;
    Messages message=messages.get(position);
    view=inflater.inflate(R.layout.message_outgoing, null);
    ProgressBar pb=(ProgressBar) view.findViewById(R.id.send_progress);
    if(message.messagePending){
        pb.setVisibility(View.VISIBLE);
    }
    else{
    pb.setVisibility(View.GONE);
        }


    TextView messageText=(TextView)view.findViewById(R.id.message_text);
    messageText.setText(message.messageText);
    return view;
}
public Messages getLastMessage(){
    return messages.get(getCount()-1);
}
public String getFormattedTime(Timestamp timeStamp){
    String timeText="";
    Date date=new Date(timeStamp.getTime());
    SimpleDateFormat displayFormat = new SimpleDateFormat(
            "MM/dd/yyyy hh:mm a");
    timeText=displayFormat.format(date);
    return timeText;
}
public void removeLastMessage() {
    messages.remove(messages.size()-1);
    notifyDataSetChanged();

}
public boolean isInitialized(){
    return init;
}
</code></pre>

<p>Here is a code in activity that does the change :</p>

<pre><code>adapter.getLastMessage().messagePending=false;
adapter.notifyDataSetChanged();
</code></pre>
