2012-08-10 107 views
2

其实我曾尝试以下方法:如何强制listview刷新其视图?

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; 
} 

因此,任何想法,我来动态改变UI的ListView

+0

什么是你的fileList?如果你使用ListView对象作为列表视图,那么使用listview.notifyDataSetChanged() – 2012-08-10 03:39:56

+0

fileList是listview的适配器。我曾尝试过类似于你的想法的方式,但它失败了!ps:listview没有方法: notifyDataSetChanged()。但适配器有! – 2012-08-10 03:41:28

+0

试试这个。 filelist = new FileList()..这个FileList应该是你的自定义适配器的自定义适配器。 listView.setAdapter(文件列表); \t \t \t \t \t \t filelist.notifyDataSetChanged(); – 2012-08-10 03:48:16

回答

0

好吧那就试试这个

listview.setAdapter(new FileList(this, R.layout.row, your data)); 

And in your FileList class make the construstor of your adapter like. 

public FileList(Context context, int textViewResourceId, String[] objects) { 
      super(context, textViewResourceId, objects); 
     } 

希望这将有助于automaticaly当你向下滚动列表视图

+0

你有没有试过了吗?你得到什么错误 – 2012-08-10 04:20:08

+0

thx为你的帮助。而且我已经尝试过,但它无法工作。我的问题是,我想交替listview'ss用户界面。 – 2012-08-10 06:10:45

+0

好的。让我检查 – 2012-08-10 06:12:20

1

getview被调用。

您的视图将automaticaly刷新

把代码中的其他条件,如果条件为假

if(checkbox_visable) 
      cb.setVisibility(View.INVISIBLE); 
else 
//what you want the state of the checkbox to be 

我认为这将工作将设置复选框的状态。

+0

thx为你的想法。尽管我的想法并没有直接帮助我,它指出我的错误。我应该设置复选框可见,但我使用了错误的值View.INVISIBLE。 – 2012-08-10 06:21:33