Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: notifyDataSetChanged() not updating listview after orientation change
    text
    copied!<p>I have a semi-complicated problem and hoping that someone here will be able to help me.</p> <p>On a click event I create a thread and start a long-running operation based on <a href="http://jnb.ociweb.com/jnb/jnbJan2009.html" rel="noreferrer">this</a> method. After the long-running task is completed, it does a callback to another method, which does a post to the handler: </p> <pre><code>@Override public void contentSearchModelChanged(Model_ContentSearch csm, ArrayList&lt;Class_Reminder&gt; newRemindersList) { remindersList = newRemindersList; mHandler.post(mUpdateDisplayRunnable); } </code></pre> <p>Which calls a Runnable:</p> <pre><code>// post this to the Handler when the background thread completes private final Runnable mUpdateDisplayRunnable = new Runnable() { public void run() { updateDisplay(); } }; </code></pre> <p>Finally, here is what my updateDisplay() method is doing:</p> <pre><code>private void updateDisplay() { if (csModel.getState() != Model_ContentSearch.State.RUNNING) { if(remindersList != null &amp;&amp; remindersList.size() &gt; 0){ r_adapter = new ReminderAdapater(Activity_ContentSearch.this, remindersList, thisListView); thisListView.setAdapter(r_adapter); r_adapter.notifyDataSetChanged(); } } } </code></pre> <p>This works beautifully when I do this normally. However, if I change the orientation while the long-running operation is running, it doesn't work. It does make the callback properly, and the remindersList does have items in it. But when it gets to this line: </p> <pre><code>r_adapter.notifyDataSetChanged(); </code></pre> <p>Nothing happens. The odd thing is, if I do another submit and have it run the whole process again (without changing orientation), it actually updates the view twice, once for the previous submit and again for the next. So the view updates once with the results of the first submit, then again with the results of the second submit a second later. So the adapater DID get the data, it just isn't refreshing the view.</p> <p>I know this has something to do with the orientation change, but I can't for the life of me figure out why. Can anyone help? Or, can anyone suggest an alternative method of handling threads with orientation changes?</p> <p>Bara</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload