自定义一个adapter继承BaseAdapter,写一个如上的方法,要更新数据时,不要调用notifyDataSetChanged()方法,调用上面的方法,即可做到更新单个item
这个艹蛋的问题,纠结了我好久。总算搞定了。。。
public void updateView(int itemIndex) {
//得到第一个可显示控件的位置,
int visiblePosition = mListView.getFirstVisiblePosition();
//只有当要更新的view在可见的位置时才更新,不可见时,跳过不更新
if (itemIndex - visiblePosition >= 0) {
//得到要更新的item的view
View view = mListView.getChildAt(itemIndex - visiblePosition);
//从view中取得holder
ViewHolder holder = (ViewHolder) view.getTag();
HashMap<String, Object> item = data.get(itemIndex);
holder.listItem = (RelativeLayout) view.findViewById(R.id.rl_item);
holder.ibPlay = (ImageButton) view.findViewById(R.id.ib_play);
holder.ibDelete = (ImageButton) view.findViewById(R.id.ib_delete);
holder.tvName = (TextView) view.findViewById(R.id.tv_record_sound_name);
holder.tvLastModifyTime = (TextView) view
.findViewById(R.id.tv_record_time);
holder.tvCurrentPlayTime = (TextView) view
.findViewById(R.id.tv_current_play_time);
holder.tvTotalTime = (TextView) view.findViewById(R.id.tv_total_time);
holder.sb = (MySeekBar) view.findViewById(R.id.pb_play);
holder.layout = (LinearLayout) view
.findViewById(R.id.play_progress_info);
updateData(itemIndex, holder, item);
}
}
网友评论