android JSON解析分页如何处理单页列表中的10项和左侧列表项转到另一页列表项
这是我的代码
public class First extends ListActivity {
private ProgressDialog pDialog;
// URL to get contacts JSON
private static String url = "http://ampndesigntest.com/pandit/contacts.css";
// JSON Node names
private static final String TAG_CONTACTS = "contacts";
private static final String TAG_ID = "id";
private static final String TAG_NAME = "name";
private static final String TAG_EMAIL = "email";
private static final String TAG_ADDRESS = "address";
private static final String TAG_GENDER = "gender";
private static final String TAG_PHONE = "phone";
private static final String TAG_PHONE_MOBILE = "mobile";
private static final String TAG_PHONE_HOME = "home";
private static final String TAG_PHONE_OFFICE = "office";
// contacts JSONArray
JSONArray contacts = null;
// Hashmap for ListView
ArrayList<HashMap<String, String>> contactList;
Button next,previous;
private TextView title;
private int increment = 0;
private int pageCount ;
public int TOTAL_LIST_ITEMS = 100;
public int NUM_ITEMS_PAGE = 10;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.first);
title=(TextView)findViewById(R.id.title);
next=(Button)findViewById(R.id.next);
previous=(Button)findViewById(R.id.prev);
previous.setEnabled(false);
contactList = new ArrayList<HashMap<String, String>>();
int val = TOTAL_LIST_ITEMS%NUM_ITEMS_PAGE;
val = val==0?0:1;
pageCount = TOTAL_LIST_ITEMS/NUM_ITEMS_PAGE+val;
ListView lv = getListView();
// Listview on item click listener
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
String name = ((TextView) view.findViewById(R.id.name))
.getText().toString();
String cost = ((TextView) view.findViewById(R.id.email))
.getText().toString();
String description = ((TextView) view.findViewById(R.id.mobile))
.getText().toString();
// Starting single contact activity
Intent in = new Intent(getApplicationContext(),
SingleContactActivity.class);
in.putExtra(TAG_NAME, name);
in.putExtra(TAG_EMAIL, cost);
in.putExtra(TAG_PHONE_MOBILE, description);
startActivity(in);
}
});
// Calling async task to get json
new GetContacts().execute();
}
/**
* Async task class to get json by making HTTP call
* */
private class GetContacts extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
pDialog = new ProgressDialog(First.this);
pDialog.setMessage("Please wait...");
pDialog.setCancelable(false);
pDialog.show();
}