Tôi có một listview đang tìm nạp dữ liệu từ cơ sở dữ liệu sqlite bởi Json.xem danh sách động thêm "Tải thêm mục" vào cuối cuộn
Tôi muốn biến nó thành chế độ xem danh sách động ở cuối cuộn, "tải thêm mục" xuất hiện trong chân của danh sách trong khi tải thêm mục và thêm chúng vào bộ điều hợp (ví dụ 10 mục mỗi lần) . Tôi gặp sự cố khi triển khai tính năng này. Xin hãy giúp tôi với nó. Cảm ơn.
public class AllProductsActivity extends Activity {
... defining variables...;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new LoadAllProducts().execute();
}
class LoadAllProducts extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
... progress dialog...
}
protected String doInBackground(String... args) {
countryList = new ArrayList<Country>();
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
Log.d("All Products: ", json.toString());
try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// products found
// Getting Array of Products
products = json.getJSONArray(TAG_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(TAG_PID);
String name = c.getString(TAG_NAME);
String description = c.getString(TAG_DESCRIPTION);
String due_date = c.getString(TAG_DUE_DATE);
String staff = c.getString(TAG_STAFF);
String status = c.getString(TAG_STATUS);
country = new Country(id,name,description,
due_date, staff, status);
countryList.add(country);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
runOnUiThread(new Runnable() {
public void run() {
displayListView();
}
});
}
}
private void displayListView() {
dataAdapter = new MyCustomAdapter(this,
R.layout.country_info, countryList);
ListView listView = (ListView) findViewById(R.id.listView1);
listView.setAdapter(dataAdapter);
}
private class MyCustomAdapter extends ArrayAdapter<Country> {
... blah blah blah ...
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
Log.v("ConvertView", String.valueOf(position));
if (convertView == null) {
... blah blah blah ...
}
return convertView;
}
}
}
Tôi có nên xác định 'item' đầu tiên visble, 'mục count' nhìn thấy và' totalitemcount'? –
không, bạn không cần phải làm như vậy. –
Tôi có nên định nghĩa chúng như thế này không: int first visible item = 1; int visibleitemcount = 10; int totalitemcount = 45; ? –