Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><s>I suppose you want to load images from Urls. For that purpose, you could use this solution: <a href="https://stackoverflow.com/questions/541966/android-how-do-i-do-a-lazy-load-of-images-in-listview/3068012#3068012">Lazy load of images in ListView</a></s></p> <p>In order to control your paging using <code>onScrollListener</code>, I think you want to see the <a href="http://benjii.me/2010/08/endless-scrolling-listview-in-android/" rel="nofollow noreferrer">Endless scrolling example</a>. This is a simplistic example, but the only thing you have to add is a check if you have reached the last item of your xml.</p> <p>Inside your <code>AsyncTask</code> (called at each new loading), you would only parse a bit of data from your xml (corresponding to 20 items in your case). This is an example of use based on your code:</p> <pre><code>public class MainGridView extends SherlockActivity implements OnScrollListener { public static final String KEY_SONG = "song"; public static final String KEY_ID = "id"; public static final String KEY_TITLE = "title"; public static final String KEY_ARTIST = "artist"; public static final String KEY_CAT_ARTIST = "artistcat"; public static final String KEY_DURATION = "duration"; public static final String KEY_THUMB_URL = "thumb_url"; public static final String KEY_BIG_URL = "big_url"; public static final String KEY_CAT_URL = "cat_url"; private final static int ITEMS_PPAGE = 20; private ProgressDialog mDialog; private ArrayList&lt;HashMap&lt;String, String&gt;&gt; mSongsList; private static String IMAGE_POSITION; private GridView mGridView; //MainGridViewLazyAdapter mAdapter; private ArrayAdapter&lt;String&gt; mAdapter; private String cat_url; private String artist_url; private int mVisibleThreshold = 5; private int mCurrentPage = 0; private int mPreviousTotal = 0; private boolean mLoading = true; private boolean mLastPage = false; private String mXml; @Override public void onCreate(Bundle savedInstanceState) { setTheme(SherlockBarUtils.getCurrentTheme(this)); super.onCreate(savedInstanceState); setContentView(R.layout.gridview_main); getSupportActionBar().setDisplayHomeAsUpEnabled(true); //checkInternetConnection(); mGridView = (GridView) findViewById(R.id.grid_view); mGridView.setOnScrollListener(this); mAdapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1); //mAdapter=new MainGridViewLazyAdapter(MainGridView.this); mGridView.setAdapter(mAdapter); new DownloadDataAsyncTask().execute(); } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (mLoading) { if (totalItemCount &gt; mPreviousTotal) { mLoading = false; mPreviousTotal = totalItemCount; mCurrentPage++; // Find your own condition in order to know when you // have finished displaying all items if (mCurrentPage + 1 &gt; 50) { mLastPage = true; } } } if (!mLastPage &amp;&amp; !mLoading &amp;&amp; (totalItemCount - visibleItemCount) &lt;= (firstVisibleItem + mVisibleThreshold)) { new AddItemsAsyncTask().execute(); mLoading = true; } } @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } public class DownloadDataAsyncTask extends AsyncTask&lt;String, String, String&gt; { @Override protected void onPreExecute() { super.onPreExecute(); mDialog = new ProgressDialog(MainGridView.this); mDialog.setTitle("Connect to Server"); mDialog.setMessage("This process can take a few seconds to a few minutes, depending on your Internet Connection Speed."); mDialog.setIndeterminate(false); mDialog.setCancelable(false); mDialog.show(); } @Override protected String doInBackground(String... args) { // Downloading XML /* Intent in = getIntent(); mSongsList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); cat_url = in.getStringExtra(KEY_CAT_URL); artist_url = in.getStringExtra(KEY_CAT_ARTIST); XMLParser parser = new XMLParser(); mXml = parser.getXmlFromUrl(cat_url); // getting XML from URL */ return null; } @Override protected void onPostExecute(String args) { /* getSupportActionBar().setTitle(artist_url); */ mDialog.dismiss(); mLoading = false; } } public class AddItemsAsyncTask extends AsyncTask&lt;Integer, String, String&gt; { @Override protected void onPreExecute() { super.onPreExecute(); } @Override protected String doInBackground(Integer... args) { MainGridView.this.runOnUiThread(new Runnable() { @Override public void run() { // Parsing 20 more items and adding them to the adapter for (int i = mCurrentPage * ITEMS_PPAGE; i &lt; (mCurrentPage + 1) * ITEMS_PPAGE; i++) { MainGridView.this.mAdapter.add(String.valueOf(Math.random() * 5000)); } MainGridView.this.mAdapter.notifyDataSetChanged(); } }); return null; } @Override protected void onPostExecute(String args) { } } } </code></pre> <p>For the convenience, I used texts instead of images inside the <code>GridView</code>. I focused on the paging system so I didn't parse XML, just added some random values on the fly. </p> <p>Also, you could consider using the same <code>addItemsAsyncTask</code> to download only a part (20 items) of your xml at each loading instead of downloading the whole 1000+ items before creating the <code>GridView</code>.</p>
    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.
 

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