我有问题。当我更新ListView
的一个视图时,我会通知一个项目。数据有2项。
但是当我用有效负载调用notifyItem
时,有效负载返回数组无。在我以不同的观点称呼成功之前,我不知道为什么。
RecyclerView
通过电话更新updateStatusIconCheckLanguage
处的一项。我检查正常更新按钮没有值有效负载。可以帮助你?感谢。
这是代码:
public class HistoryAdapter
extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private List<HistoryModel> mDataLists;
private ViewHolder mViewHolder;
private IViewCallback mCallback;
public HistoryAdapter() {
mDataLists = new ArrayList<>();
}
public void fillData(List<HistoryModel> modelList) {
if (modelList == null) {
return;
}
//remember order item.
mDataLists = new ArrayList<>();
mDataLists.addAll(modelList);
notifyDataSetChanged();
updateStatusIconCheckLanguage(KEY_TYPE_LANGUAGE.KEY_VN);
}
public void updateStatusIconCheckLanguage(KEY_TYPE_LANGUAGE keyTypeLanguage) {
if (keyTypeLanguage != null) {
if (mDataLists != null) {
for (int i = 0; i < mDataLists.size(); i++) {
notifyItemChanged(i, 34444);
CommonUtils.showLogDebug("notifyItemChanged");
}
}
}
}
public void cleanupResources() {
if (mViewHolder != null) {
mViewHolder.cleanupResources();
mViewHolder = null;
}
mDataLists = null;
// Refresh your adapter.
notifyDataSetChanged();
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent,
int viewType) {
mViewHolder = new ViewHolder(mCallback, LayoutInflater.from(parent.getContext()).inflate(R.layout.item_history, parent, false));
return mViewHolder;
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder,
int position) {
CommonUtils.showLogDebug("onBindViewHolder");
HistoryModel model = mDataLists.get(position);
if (holder instanceof ViewHolder) {
((ViewHolder) holder).fillData(model);
}
}
@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder,
final int position,
@NonNull final List<Object> payloads) {
CommonUtils.showLogDebug("ssss.size()" + payloads + holder);
if (payloads.size() > 0) {
} else {
onBindViewHolder(holder, position);
}
}
public void setOnClickItemViewListener(IViewCallback callback) {
mCallback = callback;
}
public interface IViewCallback {
void onViewClicked(HistoryModel model);
}
@Override
public int getItemCount() {
// add them 1 vi co header.
// return mNormalWithExoPlayerModelList.size();
return mDataLists == null ? 0 : mDataLists.size();
}
@Override
public int getItemViewType(final int position) {
return super.getItemViewType(position);
}
@Override
public void onViewAttachedToWindow(@NonNull final RecyclerView.ViewHolder holder) {
super.onViewAttachedToWindow(holder);
}
static class ViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.clItemHistory)
ConstraintLayout clItemHistory;
@BindView(R.id.tvItemHistory)
TextView tvItemHistory;
private Unbinder mUnbinder;
private HistoryModel mModel;
private IViewCallback mCallback;
ViewHolder(IViewCallback callback,
View view) {
super(view);
mCallback = callback;
mUnbinder = ButterKnife.bind(this, view);
}
@OnClick(R.id.clItemHistory)
protected void onViewClicked() {
if (mCallback != null) {
mCallback.onViewClicked(mModel);
}
}
void fillData(HistoryModel model) {
if ((model != null)) {
mModel = model;
tvItemHistory.setText(String.format("%s-%s-%s",
model.getDayOfHistory(),
model.getMonthOfHistory(),
model.getYearOfHistory()));
}
}
void cleanupResources() {
mModel = null;
if (clItemHistory != null) {
clItemHistory.removeAllViews();
}
if (mUnbinder != null) {
mUnbinder.unbind();
mUnbinder = null;
}
}
}
}