列表视图一次加载特定金额

时间:2014-01-27 16:11:12

标签: android facebook listview android-fragments

我的列表视图有634个项目,但我希望在用户向下滚动时将它们加载到15个组中,加载更多。

我使用片段和列表视图而不是listview片段。

获取Facebook好友的代码段(在我的案例中为634)

 public void getFriends(Session session)
    {
        Request friendsRequest = createRequest(session);

        friendsRequest.setCallback(new Request.Callback(){

            @Override
            public void onCompleted(Response response)
            {
                Log.v(TAG, "completed");
                i=new ArrayList<InvitesModel>();
                for(GraphUser g:installedUsers(getResults(response)))
                {
                    InvitesModel invitesModel=new InvitesModel();
                    invitesModel.setFname(g.getFirstName());
                    invitesModel.setLname(g.getLastName());
                    invitesModel.setId(g.getId());
                    i.add(invitesModel);
                    Collections.sort(i,new Comparator<InvitesModel>() {
                        @Override
                        public int compare(InvitesModel invitesModel, InvitesModel invitesModel2) {
                            InvitesModel i1= invitesModel;
                            InvitesModel i2=invitesModel2;
                            return (i1.getFname()+" "+i1.getLname()).compareToIgnoreCase(i2.getFname()+" "+i2.getLname());
                        }
                    });
                }
                InvitesAdapter invitesAdapter=invitesAdapter=new InvitesAdapter(getActivity(),i);
                for(InvitesModel invites:i)
                {
                invitesAdapter.add(invites);
                }
                Log.v(TAG,"fb friends"+i.size());
                lv.setAdapter(invitesAdapter);
                Log.v(TAG,"list size"+lv.getCount());
                Log.v(TAG,"adapter size"+invitesAdapter.getCount());
            }
        });

        friendsRequest.executeAsync();
    }

我的适配器

public class InvitesAdapter extends ArrayAdapter<InvitesModel> {

    private final Context context;
    private final List<InvitesModel> user;
    private String TAG="InvitesAdapter";

    public InvitesAdapter(Context context,List<InvitesModel>users) {
        super(context, R.layout.invites_row);
        this.context = context;
        this.user=users;
        Log.v(TAG,"AdapterCalled");
    }

    static class ViewHolder {
        protected RobotoLight text;
        protected RoundedImageView pic;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null)
        {
            viewHolder = new ViewHolder();
            LayoutInflater inflater = LayoutInflater.from(getContext());
            convertView= inflater.inflate(R.layout.invites_row, null);
            viewHolder.text = (RobotoLight) convertView.findViewById(R.id.invites_row_name);
            viewHolder.pic=(RoundedImageView) convertView.findViewById(R.id.invites_row_pic);
            convertView.setTag(viewHolder);
        }
        else
        {
        viewHolder = (ViewHolder) convertView.getTag();
        }
        try
        {
            UrlImageViewHelper.setUrlDrawable(viewHolder.pic, "http://graph.facebook.com/" + user.get(position).getId() + "/picture?width=200&height=200", R.drawable.profle);
        }
        catch (Exception e)
        {
            Log.e(TAG, e.getLocalizedMessage());
            viewHolder.pic.setImageResource(R.drawable.profle);
        }

        viewHolder.text.setText(user.get(position).getFname()+" "+user.get(position).getLname());

        return convertView;
    }

}

0 个答案:

没有答案