Android可扩展列表视图删除组项目混乱了视图

时间:2016-06-22 13:32:25

标签: android expandablelistview

当我尝试从可扩展列表视图中删除组时,适配器会在上部组项目中创建一个重复的视图。

所以我有以下可扩展列表视图,其中包含3个组,每个组都有一个子组: Explanation lsitview

当我尝试删除以下屏幕截图所示的名为“ Toegevoegd ”的组项时: enter image description here

listview删除了我想要的组,但问题是之前的名为“andere”的组项创建了重复 enter image description here

以下代码段显示了删除过程:

$count = 10;
$decrease_count = function() use (&$count) {
    $count--;
};
$decrease_count();
echo $count;

$added_records = 0;
Excel::filter("chunk")->selectSheetsByIndex(0)->load("storage\XYZ.xls")->chunk(250, function($reader) use (&$added_records, $part_catalogs, $parts, $cars, $car_models, $brands, &$importHelper) {
    $added_records++;
    echo "ADDED RECORDS LOCAL: " . $added_records . "<br>";
});
echo "<h2>Added " . $added_records . " records</h2>";

HeaderIterator 控制组视图, pickingLineIterator 控制每个组项的子项。

初始化适配器时,我将底层的arraylist“articleList”传递给适配器:

                for (Iterator<Header> headerIterator = articleList.iterator(); headerIterator.hasNext(); ) {
                Header header = headerIterator.next();
                if (header.getType().equals(selectedPickingLine.getType())) {
                    ArrayList<PickingLine> pickingLines = header.getPickingLineList();
                    for (Iterator<PickingLine> pickingLineIterator = pickingLines.iterator(); pickingLineIterator.hasNext(); ) {
                        PickingLine pickingLine = pickingLineIterator.next();
                        if (pickingLine.getPickingLineNr() == selectedPickingLine.getPickingLineNr()) {
                            if (selectedPickingLine.getAmount() == 0) {
                                articleRemoved = true;
                                if (pickingLines.size() == 1) {
                                    headerIterator.remove();
                                } else {
                                    pickingLineIterator.remove();
                                }
                            } else {
                                pickingLines.set(pickingLines.indexOf(pickingLine), selectedPickingLine);
                            }
                        }
                    }
                }
            }
            adapter.notifyDataSetChanged();

为什么适配器会创建重复的条目? 我调试了应用程序,底层的arraylist不包含任何重复...

1 个答案:

答案 0 :(得分:1)

对我来说,解决方案是首先崩溃我正在移除的群体。

yourListView.collapse(groupPosition);
yourListViewDataList.remove(groupPosition);
yourAdapter.notifyDataSetChanged();