android.widget.Gallery
いくつかの機能を追加するために
を拡張しました。機能の 1 つは、状況によっては特定のアイテムのみを表示する必要があることです。このために、ここに私がやったことがあります。
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 番目の子を取得する方法はありますか?
ありがとう