listview的局部刷新
2016-05-24 16:05
281 查看
listview的局部刷新,就是刷新其中某一条数据,如果只有一条数据变化的时候还执行notifyDataSetChanged方法,肯定会造成很大的性能开销
简单粗暴的说方法
然后要在适配器实现这个方法来供其调用
简单粗暴的说方法
private void updateView(int position) { //得到第一个可显示控件的位置, int visiblePosition = lv_product_list.getFirstVisiblePosition(); //只有当要更新的view在可见的位置时才更新,不可见时,跳过不更新 if (position - visiblePosition >= 0) { //得到要更新的item的view View view = lv_product_list.getChildAt(position - visiblePosition); //调用adapter更新界面 productAdapter.updateView(view, position,strPlot); } }
然后要在适配器实现这个方法来供其调用
/** * 局部刷新 * * @param view * @param itemIndex */ public void updateView(View view, int itemIndex, String strPlot) { if (view == null) { return; } //从view中取得holder ViewHolder holder = (ViewHolder) view.getTag(); // holder.tv_product_name = (TextView) view.findViewById(R.id.tv_product_name); // holder.name = (TextView) view.findViewById(R.id.name); holder.tv_pick_default_plot = (TextView) view.findViewById(R.id.tv_pick_default_plot); setData(holder, itemIndex, strPlot); } /** * 设置viewHolder的数据 * * @param holder * @param position */ private void setData(ViewHolder holder, int position, String strPlot) { // holder.tv_product_name.setText(productInfos.get(position).getProduct_name()); // holder.tv_product_permoney.setText("¥" + productInfos.get(position).getProduct_price()); // holder.tv_product_number.setText("x" + productInfos.get(position).getProduct_num()); //"选择地块"是在Activity页面动态添加 if (buffer_plotname.size() > 0 && !buffer_plotname.get(position).equals("选择")) { holder.tv_pick_default_plot.setText(strPlot); } else if (buffer_plotname.get(position).equals("")) { holder.tv_pick_default_plot.setText("选择"); } }
相关文章推荐
- 完美实现Android ListView中的TextView的跑马灯效果
- android上改变listView的选中颜色
- Delphi7中Listview的常用功能汇总
- Delphi控件ListView的属性及使用方法详解
- android中ListView数据刷新时的同步方法
- Android提高之ListView实现自适应表格的方法
- Android中实现水平滑动(横向滑动)ListView示例
- Android ListView分页功能实现方法
- C#实现ListView选中项向上或向下移动的方法
- C#下listview如何插入图片
- Listview加载的性能优化是如何实现的
- C#实现listview Group收缩扩展的方法
- C# listview添加combobox到单元格的实现代码
- ListView 百分比进度条(delphi版)
- 极致体验ajax局部和整体刷新
- Android listview多视图嵌套多视图
- ajax局部刷新一个div下jsp内容的方法
- jquery ajax 局部刷新小案例
- ListView Adapter优化 实例
- Android用ListView显示SDCard文件列表的小例子