假设我的arrayList有150个项目,我想显示分页 那么如何首次只显示前10个项目 我试过这个
arraylist.subList(0,10);
但它不起作用
编辑: 我的由Json数组组成的ArrayList看起来像:
ArrayList<HashMap<String, String>> arraylist;
UserFunctions userFunction = new UserFunctions();
JSONObject whatAreYouLooking = userFunction.getTopicsList();
arraylist = new ArrayList<HashMap<String, String>>();
try {
if (whatAreYouLooking.getString(KEY_SUCCESS) != null) {
String search_res = whatAreYouLooking.getString(KEY_SUCCESS);
if(Integer.parseInt(search_res) == 1){
jsonarray = whatAreYouLooking.getJSONArray("result");
JSONArray jsonWhatAreYouLookingArray = new JSONArray(whatAreYouLooking.optString("result"));
for (int w = 0; w < jsonWhatAreYouLookingArray.length(); w++) {
HashMap<String, String> map = new HashMap<String, String>();
JSONObject jsonLookingObject = jsonWhatAreYouLookingArray.getJSONObject(w);
map.put("topicID", jsonLookingObject.getString("topicID"));
map.put("Name", jsonLookingObject.getString("Name"));
map.put("Phone",jsonLookingObject.getString("Phone"));
arraylist.add(map);
listview = (ListView) view.findViewById(R.id.listview);
adapter = new ListViewAdapter(this.getActivity(), arraylist);
listview.setAdapter(adapter);
}
}else{
}
}else{
}
} catch (JSONException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
答案 0 :(得分:1)
ArrayList<HashMap<String, String>> arraylistsub = arraylist.subList(0,10);
listview = (ListView) view.findViewById(R.id.listview);
adapter = new ListViewAdapter(this.getActivity(), arraylistsub);
listview.setAdapter(adapter);