Deploying an infinite adapter

I get all the data from the server using doInBackground () as shown below.

class DataLoader extends Activity{ public void onCreate() { ............................... new AsyncTask1().execute(); } class AsyncTask1 extends AsyncTask<String, String, String> { @Override protected void onPreExecute() { super.onPreExecute(); progressDialog = new ProgressDialog(DataLoader.this); progressDialog.setMessage("Loading..."); progressDialog.setCancelable(false); progressDialog.show(); } protected String doInBackground(String... args) { JSONObject json; List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("param1",datafield1)); params.add(new BasicNameValuePair("param2",datafield2)); json = jsonParser.makeHttpRequest(url, "POST", params); try { int success = json.getInt(SUCCESS); if (success == 1) { products = json.getJSONArray(PRODUCTS); // looping through All Products for (int i = 0; i < products.length(); i++) { JSONObject c = products.getJSONObject(i); // Storing each json item in variable String id = c.getString(ID); String price = c.getString(PRICE); String name = c.getString(NAME); // creating new HashMap HashMap<String, String> map = new HashMap<String, String>(); // adding each child node to HashMap key => value map.put(PID, id); map.put(PRICE, price); map.put(NAME, name); .................. // adding HashList to ArrayList productsList.add(map); } return "success"; } else { // no materials found for this section } } catch (JSONException e) { e.printStackTrace(); } return null; } protected void onPostExecute(String msg) { if( msg != null && msg.equals("success")) { progressDialog.dismiss(); // updating UI from Background Thread runOnUiThread(new Runnable() { public void run() { /** * Updating parsed JSON data into ListView * */ customadapter=new CustomAdapterList(DataLoader.this, productsList); listView.setAdapter(adapter); } }); } } } 

According to the code above, I set the data in listview in the onPostExecute() method only after loading all the data. But now I want to implement the CW Endless Adapter with real code, but since I'm new to this, I cannot figure out how to move on from here. I included the jar file CWAdapter in the libs folder. They took this and searched a lot, but did not use it. Can someone please help me implement an infinite function for the data I receive?

+4
source share
1 answer

The basic idea is to start AsyncTask when more data is needed, that is, when a scroll is used at the bottom of the list. Here's a quick demo project .

+3
source

All Articles