我有这样的组布局:
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="6dp"
android:background="@color/listViewItemBackground">
<TextView
android:id="@+id/tvGroupName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.Medium"
android:singleLine="false"
android:layout_weight="1" />
<ImageView
android:id="@+id/ivGroupIcon"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</LinearLayout>
在我的 ViewHolder getGroupView
中,我执行以下操作:
if (group.children != null && group.children.size() > 0) {
if (isExpanded) {
holder.ivGroupIcon.setImageResource(R.drawable.group_up);
} else {
holder.ivGroupIcon.setImageResource(R.drawable.group_down);
}
}
我有 4 个小组,其中只有 2 个小组有 child 。当我展开/折叠各个组时,没有 child 的组也会显示一个图标。
这是 Android 问题还是我的代码有问题?
最佳答案
您可能会使用 else
部分:
if (group.children != null && group.children.size() > 0) {
if (isExpanded) {
holder.ivGroupIcon.setImageResource(R.drawable.group_up);
} else {
holder.ivGroupIcon.setImageResource(R.drawable.group_down);
}
} else {
holder.ivGroupIcon.setImageDrawable(null);
}
关于android - 可扩展的 ListView 组 View 指示器显示在错误的组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31101720/