请问大神,为什么,我在给RecycleView的adapter的加载list更新了,notifyDataSetChanged()无效,未更新
。
代码如上,我使用了代码
获取bind()方法里的Log,发现list是改变了的,但是notifyDataSetChanged()无效。
求大神帮助!!!
。
package sunland.com.itaxi.ui.illegal;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import sunland.com.itaxi.R;
import sunland.com.itaxi.bean.IllegalBean;
import sunland.com.itaxi.bean.IllegalTypeBean;
import sunland.com.itaxi.bean.PlateListBean;
import sunland.com.itaxi.ui.punish.penalties.PenaltiesActivity;
/**
* Created by zjl on 2016/9/21.
*/
public class IllegalAdapter extends RecyclerView.Adapter<IllegalAdapter.MyViewHolder> {
private List<IllegalBean> list;
private Context context;
private int type;
private int platform;
private ArrayList<IllegalTypeBean> typelist = new ArrayList<>();
private ArrayList<PlateListBean> platformlist = new ArrayList<>();
@Inject
public IllegalAdapter(Context context) {
this.context = context;
}
public void bind(List<IllegalBean> list) {
Log.d("zjlsize+",""+list.size());
this.list = list;//list赋值是改变了
//notifyDataSetChanged();里面写也是无效的
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_illegal_recycleview_item, parent, false);
MyViewHolder holder = new MyViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
holder.pos = position;
Log.d("zjl**istrue", "*" + list.get(position).isIsTrue());
if (!list.get(position).isIsTrue()) {
holder.hide_rl.setVisibility(View.VISIBLE);
holder.hide_rl.getBackground().setAlpha(204);
holder.ifclick = 0;
} else {
holder.hide_rl.setVisibility(View.GONE);
holder.ifclick = 1;
}
if (list.get(position).getGender() == 0) {
holder.offender_portrait_rv.setImageDrawable(context.getResources().getDrawable(R.drawable.woman));
} else {
holder.offender_portrait_rv.setImageDrawable(context.getResources().getDrawable(R.drawable.man));
}
}
@Override
public int getItemCount() {
return list.size();
}
public interface OnItemClickLitener {
void onItemClick(IllegalBean illegalBean, int position);
}
private OnItemClickLitener mOnItemClickLitener;
public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener) {
this.mOnItemClickLitener = mOnItemClickLitener;
}
class MyViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.activity_illegal_recycleview_item_show_rl)
RelativeLayout show_rl;
@BindView(R.id.activity_illegal_recycleview_item_hide_rl)
RelativeLayout hide_rl;
@BindView(R.id.offender_portrait_rv)
ImageView offender_portrait_rv;
@BindView(R.id.offender_name_tv)
TextView offender_name_tv;
@BindView(R.id.offender_vehicleNum_tv)
TextView offender_vehicleNum_tv;
@BindView(R.id.offender_illegal_date_tv)
TextView offender_illegal_date_tv;
@BindView(R.id.offender_illegal_type_tv)
TextView offender_illegal_type_tv;
@BindView(R.id.offender_illegal_place_tv)
TextView offender_illegal_place_tv;
@BindView(R.id.offender_carinfo_platform_tv)
TextView offender_carinfo_platform_tv;
@BindView(R.id.offender_carinfo_area_tv)
TextView offender_carinfo_area_tv;
@BindView(R.id.offender_describe_tv)
TextView offender_describe_tv;
@BindView(R.id.offender_carsource_iv)
ImageView offender_carsource_iv;
IllegalBean illegalBean;
int pos;
int ifclick = 1;//是否可点击
@OnClick(R.id.activity_illegal_recycleview_item_show_rl)
void listItemClick() {
if (mOnItemClickLitener != null) {
if (ifclick == 0) {
//对“正在处理中”的处理
} else {
mOnItemClickLitener.onItemClick(list.get(pos), pos);
}
}
}
public MyViewHolder(View view) {
super(view);
ButterKnife.bind(this, view);
}
}
}
代码如上,我使用了代码
adapter.bind(illegallist);
adapter.notifyDataSetChanged();
获取bind()方法里的Log,发现list是改变了的,但是notifyDataSetChanged()无效。
求大神帮助!!!