0


我已经扩展了android.widget.Gallery添加一些功能。其中一项功能是在某些情况下我需要仅显示某些项目。为此,这就是我所做的。

public void displayChildViews(Integer... indices) {

    boolean showAll = indices.length == 0;

    if (indices.length > this.getChildCount())
        throw new IllegalArgumentException(
                String.format(
                        "Number of indices (%d) cannot be larger then the gallery child count (%d)",
                        indices.length, this.getCount()));

    List<Integer> showIndices = Arrays.asList(indices);

    for (int i = 0; i < this.getCount(); i++) {
        int visibility = showAll || showIndices.contains(i) ? View.VISIBLE : View.INVISIBLE;
        this.getChildAt(i).setVisibility(visibility);
    }       
}

这是我的问题。首先,我尝试使用 遍历子项,this.getChildCount()但它只返回可见项目的数量(在我的例子中是图像),并没有返回画廊的所有子项目的数量。所以为了克服这个问题,我使用this.getCount了返回正确数量的子项(根据适配器)。问题是我需要设置所有子项的可见性,但返回可见this.getChildAt(i)子项的第 i个子项,而不是具有正确索引的真正子项。现在有没有办法得到真正的第 i 个孩子? 谢谢

4

0 回答 0