Skip to content

Commit

Permalink
添加注释
Browse files Browse the repository at this point in the history
  • Loading branch information
lzx authored and lzx committed Oct 22, 2016
1 parent 261a84e commit efc6353
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions app/src/main/java/com/lzx/demo/ui/PartialRefreshActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,39 +97,39 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
TLog.error("onBindViewHolder 00000");
ItemModel itemModel = mDataList.get(position);

ViewHolder viewHolder = (ViewHolder) holder;

viewHolder.textView.setText(itemModel.title);
Glide.with(mContext)
.load(itemModel.imgUrl)
.crossFade()
.placeholder(R.mipmap.icon)
.into(viewHolder.avatarImage);
bind(holder,position);
}

//局部刷新关键:带payload的这个onBindViewHolder方法必须实现
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position, List payloads) {
TLog.error("onBindViewHolder payloads.isEmpty() ? " + payloads.isEmpty());
TLog.error("onBindViewHolder payloads.isEmpty() ? " + payloads.isEmpty() );
if (payloads.isEmpty()) {
onBindViewHolder(holder,position);
} else {//更新想更新的控件
ItemModel itemModel = mDataList.get(position);
} else {//需要更新的数据
TLog.error("onBindViewHolder payloads.size() = " + payloads.size());

ViewHolder viewHolder = (ViewHolder) holder;
//notifyItemChanged(int position, Object payload) 要与payload的类型保持一致
if (payloads.get(0) instanceof Integer) {
bind(holder,position);
}

viewHolder.textView.setText(itemModel.title);

Glide.with(mContext)
.load(itemModel.imgUrl)
.placeholder(R.mipmap.icon)
.into(viewHolder.avatarImage);
}
}

private void bind(RecyclerView.ViewHolder holder, int position) {
ItemModel itemModel = mDataList.get(position);

ViewHolder viewHolder = (ViewHolder) holder;

viewHolder.textView.setText(itemModel.title);

Glide.with(mContext)
.load(itemModel.imgUrl)
.placeholder(R.mipmap.icon)
.into(viewHolder.avatarImage);
}

@Override
public int getItemCount() {
return mDataList.size();
Expand Down Expand Up @@ -161,15 +161,16 @@ public boolean onOptionsItemSelected(MenuItem item) {
} else if (item.getItemId() == R.id.menu_partial_refresh) {

int position = 1;//指定列表中的第2个item
//改变第4个item值

ItemModel itemModel = mDataAdapter.getDataList().get(position);
itemModel.id = 100;
itemModel.title = "refresh item " + itemModel.id;
itemModel.imgUrl = "http://avatar.csdn.net/2/9/C/1_jdsjlzx.jpg";
mDataAdapter.getDataList().set(position,itemModel);

//RecyclerView局部刷新 详见:https://github.com/jdsjlzx/LRecyclerView/issues/45
mLRecyclerViewAdapter.notifyItemChanged(mLRecyclerViewAdapter.getAdapterPosition(false,position) ,mDataAdapter.getDataList());
// notifyItemChanged(int position, Object payload) 其中的payload相当于一个标记,类型不限
mLRecyclerViewAdapter.notifyItemChanged(mLRecyclerViewAdapter.getAdapterPosition(false,position) , position);

}
return true;
Expand Down

0 comments on commit efc6353

Please sign in to comment.