如何在获取并显示领域中的每100条记录后触发更多内容

时间:2016-12-18 05:42:27

标签: android android-recyclerview realm

以下地址中的Realm recyclerview:realmrecyclerview具有loadmore功能,并且有一个示例项目创建一个60领域对象,然后查询领域并将查询结果设置为recyclerview的适配器。滚动recyclelerview以结束onloadmore listner在loadmore函数中被激活另一个异步方法被调用,它创建另外60个对象并保存到领域,然后recyclelerview显示新对象。 我想使用这个loadmore功能来分页大数据集查询。我试图在onloadmore函数中查询但是适配器没有用新的查询结果进行查询。但是当我重新创建适配器并设置为recyclerview时,它正在工作。

1 个答案:

答案 0 :(得分:0)

这是我的realmrecyclerview扩展抽象的RealmBasedRecyclerViewAdapter类:`public class QuoteRecyclerViewAdapter extends RealmBasedRecyclerViewAdapter {

    public QuoteRecyclerViewAdapter(
            Context context,
            RealmResults<QuoteModel> realmResults,
            boolean automaticUpdate,
            boolean animateIdType,
            String animateExtraColumnName) {
        super(context, realmResults, automaticUpdate, animateIdType, animateExtraColumnName);
    }

    public class ViewHolder extends RealmViewHolder {

        public FrameLayout container;

        public TextView quoteTextView;

        public TextView footerTextView;

        public ViewHolder(FrameLayout container) {
            super(container);
            this.container = container;
            this.quoteTextView = (TextView) container.findViewById(R.id.quote_text_view);
            this.footerTextView = (TextView) container.findViewById(R.id.footer_text_view);
        }
    }

    @Override
    public ViewHolder onCreateRealmViewHolder(ViewGroup viewGroup, int viewType) {
        View v = inflater.inflate(R.layout.item_view, viewGroup, false);
        return new ViewHolder((FrameLayout) v);
    }

    @Override
    public void onBindRealmViewHolder(ViewHolder viewHolder, int position) {
        final QuoteModel quoteModel = realmResults.get(position);
        viewHolder.quoteTextView.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (!quoteModel.isValid()) {
                            return;
                        }
                        asyncRemoveQuote(quoteModel.getId());
                    }
                }
        );
        viewHolder.quoteTextView.setOnLongClickListener(
                new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View v) {
                        asyncUpdateQuote(quoteModel.getId());
                        return true;
                    }
                }
        );
        if (type != null && type.equals("Grid")) {
            viewHolder.container.setBackgroundColor(
                    colors.get((int) (quoteModel.getId() % colors.size())));
        }
        viewHolder.quoteTextView.setText(quoteModel.getQuote());
    }

    @Override
    public void onBindFooterViewHolder(ViewHolder holder, int position) {
        holder.footerTextView.setText("I'm a footer");
    }

    @Override
    public ViewHolder onCreateFooterViewHolder(ViewGroup viewGroup) {
        View v = inflater.inflate(R.layout.footer_view, viewGroup, false);
        return new ViewHolder((FrameLayout) v);
    }
}`