Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is the way I finally solved it (after many iterations and different implementations). It's a bit tricky but basically you need three things:</p> <ol> <li>An AsyncTask that gathers meta data</li> <li>A scroll listener that tells us when the user has stopped scrolling/flinging</li> <li>A clever algorithm that finds any visible row that needs updating and asks the adapter to only update that specific row</li> </ol> <p>This is the way I designed and implemented it:</p> <p><img src="https://raw.github.com/slidese/SGU/master/2013-11-25-14.45.00.png" alt="Screenshot"></p> <p>I wrote in more detail about <a href="http://slidese.github.io/slidese/2013/11/25/update_listview_item.html" rel="noreferrer">it here</a>, and please see the <a href="https://github.com/slidese/SGU/blob/3be1888115ba56b4a015b127b249c35af5dc11d0/src/se/slide/sgu/ContentFragment.java" rel="noreferrer">github code</a> for the complete imlementation.</p> <pre><code> private class UpdaterAsyncTask extends AsyncTask&lt;Void, Void, Void&gt; { boolean isRunning = true; public void stop() { isRunning = false; } @Override protected Void doInBackground(Void... params) { while (isRunning) { // Gather data about your adapter objects // If an object has changed, mark it as dirty publishProgress(); try { Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } } return null; } @Override protected void onProgressUpdate(Void... params) { super.onProgressUpdate(); // Update only when we're not scrolling, and only for visible views if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) { int start = mListview.getFirstVisiblePosition(); for(int i = start, j = mListview.getLastVisiblePosition(); i&lt;=j; i++) { View view = mListview.getChildAt(i-start); if (((Content)mListview.getItemAtPosition(i)).dirty) { mListview.getAdapter().getView(i, view, mListview); // Tell the adapter to update this view } } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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