gpt4 book ai didi

android - android ListView 中的异常

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:16:10 26 4
gpt4 key购买 nike

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

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

最佳答案

通过子代码解决这个错误:

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

关于android - android ListView 中的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34532679/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com