Android observer is not updating object in listview
<p>I am having troubles using <code>java.util.Observable</code> in my android application.
In my app, I want to update a <code>listview</code> when the data is changed in the background.</p>

<p>So the objects from the <code>listview</code> are in the observer. I see them in the <code>arraylist</code> from the observer class. In Eclipse Debugging I see the reference to my objects, for example: <code>at.stockserv.todo.Todo@1a3f2cb7</code> </p>

<p>One thing I don't understand: When the data is changed in my observer update method</p>

<pre><code>@Override
public void update(Observable observable, Object data) {        
    if (observable instanceof DBObjectUpdateObserver) {         
        ObserverMessage message = (ObserverMessage) data;           
        if (message.getAction() == Actions.messageIdChanged) {
            if (message.getData().get("oldId").equals(Integer.valueOf(getId()))) {
                setId((Integer) message.getData().get("newId"));
                DBObjectUpdateObserver.getInstance().dataHasChanged(this);

            }
        }
    }   

}
</code></pre>

<p>After setId, suddenly the object has another reference. So in my <code>listview</code>, still the old data is stored with the old reference. </p>

<p>My code in the view:</p>

<pre><code>@Override
public void update(Observable observable, Object data) {        
    ObserverMessage message = (ObserverMessage) data;
    if (message.getAction() == Actions.messageDBDataChanged) {          
        if (actNotices.contains(message.getData().get("dbObject"))) {               
            notifyDataSetChanged();             
            Toast.makeText(getApplicationContext(), "Data is updated ", Toast.LENGTH_LONG).show();              
        }           
    }

}
</code></pre>

<p><code>actNotices</code> ist the <code>arraylist</code> with data in the <code>adapter</code>. The data is here not changed, but the data should be changed from the first method. </p>

<p>My code of the observer is:</p>

<pre><code>public class DBObjectUpdateObserver extends Observable {

 private static DBObjectUpdateObserver instance = new DBObjectUpdateObserver();

 public static DBObjectUpdateObserver getInstance() {
        return instance;
 }

 private DBObjectUpdateObserver() { 

 }

 public void updateId (DBCommunicator dbObject, int oldId, int newId) {
     HashMap&lt;String, Object&gt; data = new HashMap&lt;String, Object&gt;();
     data.put("oldId", oldId);
     data.put("newId", newId);
     data.put("dbObject", dbObject);
     getInstance().setChanged();
     getInstance().notifyObservers(new ObserverMessage(Actions.messageIdChanged, data));         

 }

 public void dataHasChanged(DBCommunicator dbObject, int oldId, int newId) {
     HashMap&lt;String, Object&gt; data = new HashMap&lt;String, Object&gt;();       
     data.put("dbObject", dbObject);
     data.put("oldId", oldId);
     data.put("newId", newId);
     getInstance().setChanged();
     getInstance().notifyObservers(new ObserverMessage(Actions.messageDBDataChanged, data));         
 }    
</code></pre>

<p>}</p>

<p>What I don't understand is:
The object in the <code>arraylist</code> is added to the observer. Some data in the observer object is changed. But the changes are only in the object of the observer, not in the arraylist which I added to the observer. I thought that in the observer there is just a reference to my object in the <code>arraylist</code>? So the object in the <code>arraylist</code> should change as well when the object in the observer is changed. But this does not work, why?</p>

<p>Can anyone explain me what is happening here?</p>