我通过使用doInBackground()方法,如下所示从服务器获取的全部数据。
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);
}
});
}
}
}
按照上面的代码,我的数据设置为listview
中onPostExecute()
的整个数据被加载后,才方法。 但现在我要实现的CW Endless Adapter
本代码,但因为我是新来这个,我无法获得如何从这里移动。 我包括libs文件夹中的CWAdapter jar文件。 都提到这并搜查了很多,但没有用。 有人可以帮我实现了数据,我得到了无尽的功能?