【问题标题】:exception in list view in androidandroid列表视图中的异常
【发布时间】:2015-12-30 15:50:35
【问题描述】:

我在列表视图中添加了标题 过去向上或向下滚动时抛出异常 这是通过自定义视图列表解决的:

    public MyFixedListView(Context context) {
    super(context);
}

public MyFixedListView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public MyFixedListView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}

public MyFixedListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
}


@Override
protected void dispatchDraw(Canvas canvas) {
    try {
        super.dispatchDraw(canvas);
    } catch (IndexOutOfBoundsException e) {
        e.printStackTrace();
    }

}

但是现在Android 6.0.1 (marshmallow) ,再次显示以前的错误: 在我的堆栈中:

java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0 : at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)

添加标题:

private void Create_Header_Sjd_init() {

    LayoutInflater  inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
    convertViewHeader = inflater.inflate(R.layout.row_idea_list , null);
    convertViewHeader.setBackgroundColor(getResources().getColor(R.color.gray_light_light));

    listView.addHeaderView(convertViewHeader, null, false);
}

【问题讨论】:

  • 页眉/页脚是静态的还是滚动的?
  • 它们也可以滚动@Tasos
  • 如果您发现任何可能有帮助的内容,请查看本教程 -- youtube.com/watch?v=8wOO91oLo2s
  • 请出示您的自定义适配器

标签: android listview scroll adapter android-6.0-marshmallow


【解决方案1】:

通过子代码解决此错误:

        listView.setFooterDividersEnabled(false);
    listView.addFooterView(new View(this), null, false);

【讨论】:

    【解决方案2】:

    IndexOutOfBoundsException,也许您可​​以检查有关数据列表或项目视图的代码

    【讨论】:

    • 我用了无穷无尽的列表,很困难
    【解决方案3】:

    如果您的列表大小 id 为零,那么对于将标题添加到列表视图,您已经设置了这个..

    listView.setAdapter(null);
    

    【讨论】:

    • 注释这行代码:addHeaderView() never throw exception
    • 请告诉我您何时调用 addHeaderView()。您是否在 onScroll() 中调用它
    • 我只调用了一次 addheader() 并且第一次加载
    猜你喜欢
    • 2014-05-19
    • 1970-01-01
    • 2015-04-11
    • 2011-12-24
    • 1970-01-01
    • 2012-07-24
    • 2021-10-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多