是否有一种方法可以在分页中显示Arraylist项目



说我的arraylist有150个我想显示的分页因此,如何首次仅显示前10个项目我尝试了这个

arraylist.subList(0,10);

但不起作用

编辑:我的阵列列表由JSON阵列组成,看起来像:

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);

最新更新