在从服务器获取此数据并单击视图不更新
我的问题是:点击(收藏夹)按钮,当我滚动视图时,它会改变点击按钮的位置。
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
if (holder instanceof StudentViewHolder) {
OfficeData list = (OfficeData) adapterList.get(position);
final HashMap < String, Object > detailMap = list.getMapMain();
try {
((StudentViewHolder) holder).gView.setTag(list.getMapMain());
if (detailMap.containsKey((ConstVariable.FAVOURITESTATUS)) && detailMap.get(ConstVariable.FAVOURITESTATUS) != null) {
if (detailMap.get(ConstVariable.FAVOURITESTATUS).toString().equals("red")) {
Log.e("testing", "3");
((StudentViewHolder) holder).imagehart.setBackgroundResource(R.drawable.heart_green);
((StudentViewHolder) holder).imagehart.setChecked(true);
}
if (detailMap.get(ConstVariable.FAVOURITESTATUS).toString().equals("default")) {
Log.e("testing", "4");
((StudentViewHolder) holder).imagehart.setBackgroundResource(R.drawable.heart);
((StudentViewHolder) holder).imagehart.setChecked(false);
}
}
}
((StudentViewHolder) holder).imagehart.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view) {
if (((StudentViewHolder) holder).imagehart.isChecked()) {
Utils.global.mapData.clear();
Utils.global.mapData.put(ConstVariable.MODE, (ConstVariable.UNFAV).toString()); //used for unFavorite
((StudentViewHolder) holder).imagehart.setBackgroundResource(R.drawable.heart);
((StudentViewHolder) holder).imagehart.setChecked(false);
Utils.global.mapData.put(ConstVariable.VIDEOPOSTID, detailMap.get(ConstVariable.VIDEOID).toString());
JsonPost.getAddFavorite(Utils.context, null, "ASC", "");
Toast toast = Toast.makeText(Utils.context, "Unfavourite", Toast.LENGTH_SHORT);
toast.show();
} else {
Utils.global.mapData.clear();
Utils.global.mapData.put(ConstVariable.MODE, (ConstVariable.FAV).toString()); //used for Favorite
Utils.global.mapData.put(ConstVariable.VIDEOPOSTID, detailMap.get(ConstVariable.VIDEOID).toString());
((StudentViewHolder) holder).imagehart.setBackgroundResource(R.drawable.heart_green);
((StudentViewHolder) holder).imagehart.setChecked(true);
JsonPost.getAddFavorite(Utils.context, null, "ASC", "");
Toast toast = Toast.makeText(Utils.context, "Favourite", Toast.LENGTH_SHORT);
toast.show();
Log.e("click", "2");
}
}
}
);
} catch (Exception e) {
Utils.e("EventDataAdapter 155", "Exception======================Exception======================Exception");
e.printStackTrace();
}
((StudentViewHolder) holder).officeData = list;
}
}
public void setLoaded() {
loading = false;
}
@Override
public int getItemCount() {
if (adapterList != null) {
return adapterList.size();
} else {
return 0;
}
}
public static class StudentViewHolder extends RecyclerView.ViewHolder {
public View gView;
public OfficeData officeData;
CheckedTextView imagehart;
public StudentViewHolder(View v) {
super(v);
this.setIsRecyclable(false);
gView = v;
try {
imagehart = (CheckedTextView) itemView.findViewById(R.id.image_hart);
} catch (Exception e) {
Utils.e("ProfileEventRecycle 173", "Exception======================Exception======================Exception");
e.printStackTrace();
}
}
}
public static class ProgressViewHolder extends RecyclerView.ViewHolder {
public ProgressBar progressBar;
public ProgressViewHolder(View v) {
super(v);
progressBar = (ProgressBar) v.findViewById(R.id.progressBar12);
}
}
}