我正在编写一个需要隐藏可扩展列表视图元素的应用程序。
这就是我正在做的事情。
public View getGroupView(int groupPosition, boolean isLastChild, View view,
ViewGroup parent) {
CardHeaderInfo headerInfo = (CardHeaderInfo) getGroup(groupPosition);
if (view == null) {
LayoutInflater inf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inf.inflate(R.layout.card_group_view, null);
}
if(groupPosition < validChild) {
TextView heading = (TextView) view.findViewById(R.id.heading);
heading.setText(headerInfo.getName().trim());
} else {
view.setVisibility(View.INVISIBLE);
}
return view;
}
为了优化这里的工作,我使用了 ViewHolder概念,但是如果开始滚动列表,则元素会随机播放,即使某些变量被隐藏视图替换。
在使用 ViewHolder 的时候有什么办法可以摆脱这个问题吗?