其实我试过以下方法:
checkbox_visable=true;
fileList.notifyDataSetChanged();
listview.invalidate();
但它就是无法为每一行调用我指定的适配器的 getview()
方法:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
convertView=super.getView(position, convertView, parent);
CheckBox cb=(CheckBox) convertView.findViewById(R.id.item_cb);
if(checkbox_visable)
cb.setVisibility(View.INVISIBLE);
return convertView;
}
那么,我有什么想法可以动态更改 ListView
的 UI 吗?
最佳答案
当您向下滚动 ListView 时,会自动调用 getview。
你的 View 会自动刷新
在您的代码中放置一个 else 条件,如果条件为假,它将设置复选框的状态
if(checkbox_visable)
cb.setVisibility(View.INVISIBLE);
else
//what you want the state of the checkbox to be
我认为这会奏效。
关于android - 如何强制 ListView 刷新它的 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11895121/