Giter Site home page Giter Site logo

Comments (6)

CymChad avatar CymChad commented on May 1, 2024

感谢提出来的问题,今天内给你答复。

from baserecyclerviewadapterhelper.

lucklygaj avatar lucklygaj commented on May 1, 2024

你好,你说的这个重新实例个Adapter与clear()哪个更好,我认为应该视情况而定,因为clear()也就是遍历里面元素然后置Null,你重新实例一个也要考虑重新实例对象是比较耗费资源的,当你data集合的size()不是很大时,clear()相信会是个更好的选择,你提出的异常我们会及时查找并修复,希望能提供下异常的报错信息,方便我们及时修复,谢谢你的反馈

from baserecyclerviewadapterhelper.

lucklygaj avatar lucklygaj commented on May 1, 2024

你一开始如果无data的话,可以指定为null,后面我们会提供一个不需要制定data的构造方法

from baserecyclerviewadapterhelper.

tsunamilx avatar tsunamilx commented on May 1, 2024

IndexOutOfBoundsException:

java.lang.IndexOutOfBoundsException: Invalid index 1, size is 0
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
at java.util.ArrayList.add(ArrayList.java:147)
at com.chad.library.adapter.base.BaseQuickAdapter.add(BaseQuickAdapter.java:146)
at com.example.ArticlesFragment.addArticle(ArticlesFragment.java:78)

我一开始在初始化Adapter的时候给了null的data,报了这个错,然后给了个size为20的ArrayList,还是抱这个错

private class ArticlesAdapter extends BaseQuickAdapter<Article> {

    public ArticlesAdapter(Context context) {
        super(context, R.layout.article_item, new ArrayList<Article>(20));
        openLoadAnimation();
    }

    @Override
    protected void convert(BaseViewHolder helper, Article article) {
        helper.setText(R.id.article_title, article.getTitle());
    }
}

我是对数据进行逐一添加的:

@Override
public void addArticle(int position, Article article) {
    // 这个会导致 IndexOutOfBoundsException
    adapter.add(position, article);

    // 我目前是这样解决的:
    adapter.getData().add(article);
    adapter.notifyItemInserted(position);
}

from baserecyclerviewadapterhelper.

tsunamilx avatar tsunamilx commented on May 1, 2024

哦,抱歉,犯了个低级错误,IndexOutOfBoundsException是我ArrayList使用不当...:flushed::flushed::flushed:

from baserecyclerviewadapterhelper.

lucklygaj avatar lucklygaj commented on May 1, 2024

已修复,新增了API,

from baserecyclerviewadapterhelper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.