如何不调用notifyDataSetChanged()时更新ListView的某一项数据

来源:互联网 发布:合肥网络招聘会 编辑:程序博客网 时间:2024/06/08 19:13

通过结合使用View#getChildAt(int index)和ListView#getFirstVisiblePosition(). 
示例如下:

public boolean updateListView(int position, int newProgress) {int first = mListView.getFirstVisiblePosition();int last = mListView.getLastVisiblePosition();if(position < first || position > last) {    //just update your DataSet    //the next time getView is called    //the ui is updated automatically    return false;}else {    View convertView = mListView.getChildAt(position - first);    //this is the convertView that you previously returned in getView    //just fix it (for example:)    ProgressBar bar = (ProgressBar) convertView.findViewById(R.id.progress);    bar.setProgress(newProgress);    return true;}}

方法取自StackOverFlow:
[1] http://stackoverflow.com/questions/3724874/how-can-i-update-a-single-row-in-a-listview
[2]http://stackoverflow.com/questions/19025841/how-to-update-some-data-in-a-listview-without-using-notifydatasetchanged

0 0
原创粉丝点击