updating an adapter's dataset without changing the view being displayed
<p>I'm using a <code>ViewPager</code> to display articles in a magazine e-reader app. When the app initializes, it pulls 10 articles from a web service and uses them to inflate 10 views, which are passed to the <code>PagerAdapter</code>. When the user reaches the sixth view (when the size of the article array minus the current position is less than four), I want to load 10 more articles and add them to the end of the PagerAdapter's views, such that when the user reaches the 10th article, the next 10 will already be loaded. This seems to be working fine with the following code: </p>

<pre><code>        @Override
    public Object instantiateItem(View arg0, int position) {

    final Article a = toShow.get(position);
    View v = makeView(a);
    ((ViewPager) arg0).addView(v);

    outer: if (toShow.size() - position &lt; 4 &amp;&amp; noMore == false){
        ArrayList&lt;Article&gt; toAdd = new ArrayList&lt;Article&gt;();
        int idx = toShow.size()-1;
        try {
            toAdd = new getPosts(idx).execute().get();
                } catch (InterruptedException e) {e.printStackTrace();
                } catch (ExecutionException e) {e.printStackTrace();}
        idx++;

        if (toAdd.isEmpty()){
            noMore = true;
            break outer;
        }
        else {
        for (int curr = 0; curr &lt; toAdd.size(); curr++){
            toShow.add(idx, toAdd.get(curr));
        }
        this.notifyDataSetChanged();
        System.out.println("added more");           
    }
    }

    return v;
        }
</code></pre>

<p>except that, when the dataset is changed (i.e. when the new articles finish loading and are added to the <code>PagerAdapter</code>), the <code>ViewPager</code> goes back to the displaying the first view. How can I change my approach here so that new articles can be loaded without altering the view being displayed currently?</p>
