有没有一种方法可以在分页中显示arraylist项目? [英] Is there a way to show arraylist items in paging?
本文介绍了有没有一种方法可以在分页中显示arraylist项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我的arrayList有150个项目,我想显示分页那么第一次如何只显示前10个项目我尝试过
Say my arrayList have 150 items i wanna show paging So how display only first 10 items first time I tried with this
arraylist.subList(0,10);
但它不起作用
我的由Json数组组成的ArrayList看起来像:
Edited : My ArrayList made up from Json array looks like :
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();
}
推荐答案
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);
这篇关于有没有一种方法可以在分页中显示arraylist项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文