public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
View view = convertView;
if (view == null) {
view = LayoutInflater.from(MainActivity.this).inflate(
R.layout.view_ass_list, null);
holder = new ViewHolder();
holder.ivAssImg = (ImageView) view.findViewById(R.id.iv_ass);
holder.ivOverflow = (ImageView) view
.findViewById(R.id.iv_overflow);
holder.tvAssName = (TextView) view
.findViewById(R.id.tv_view_name);
holder.tvAssDesc = (TextView) view
.findViewById(R.id.tv_view_description);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
final Ass ass = getItem(position);
holder.ivOverflow.setImageResource(R.drawable.ic_action_overflow);
holder.ivAssImg
.setImageURI(Uri.fromFile(new File(ass.getAss_img())));
holder.tvAssName.setText(ass.getAss_name());
holder.tvAssDesc.setText(ass.getAss_desc());
holder.ivOverflow.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onClickOverflow(ass, v);
}
});
return view;
}
上面是继承BaseAdapter的getView()方法,就是当我点击ListView的某一项时会变色,但是拉到下面时,发现别的没点也变色。我知道是因为优化的时候重复使用到了之前的view,但是不懂得如何改。。