解決辦法:看代碼
創(chuàng)新互聯(lián)專注于企業(yè)成都全網(wǎng)營銷、網(wǎng)站重做改版、昆都侖網(wǎng)站定制設(shè)計、自適應(yīng)品牌網(wǎng)站建設(shè)、H5網(wǎng)站設(shè)計、成都商城網(wǎng)站開發(fā)、集團公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為昆都侖等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
package com.zhiren.coaltransportsystem.adapters; import android.content.Context; import android.os.Handler; import android.os.Message; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; import com.zhiren.coaltransportsystem.R; import com.zhiren.coaltransportsystem.activities.Stationed_List_Activity; import com.zhiren.coaltransportsystem.bean.ChoseAddressBean; import java.util.List; /** * Created by Administrator on 2016/6/3. */ public class LocationAdapter extends BaseAdapter { private Context context; private List list; private ImageView icon; private Handler handler; public LocationAdapter(List list, Context context, Handler handler) { this.list = list; this.context = context; this.handler = handler; } @Override public int getCount() { return list.size(); } @Override public Object getItem(int position) { return list.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (position > list.size() || position < 0) { return convertView; } ViewHolder viewHolder = null; if (convertView == null) { viewHolder = new ViewHolder(); convertView = View.inflate(context, R.layout.find_address_item, null); viewHolder.iv_icon_chose = (ImageView) convertView.findViewById(R.id.iv_icon_chose); viewHolder.tv_addressname_item = (TextView) convertView.findViewById(R.id.tv_addressname_item); viewHolder.rl_icon_item = (RelativeLayout) convertView.findViewById(R.id.rl_icon_item); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } viewHolder.iv_icon_chose.setVisibility(View.GONE); final ChoseAddressBean choseAddressBean = (ChoseAddressBean) list.get(position); viewHolder.tv_addressname_item.setText(choseAddressBean.name); final ViewHolder finalViewHolder = viewHolder; viewHolder.rl_icon_item.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { icon.setVisibility(View.GONE); finalViewHolder.iv_icon_chose.setVisibility(View.VISIBLE); icon = finalViewHolder.iv_icon_chose; Message msg = Message.obtain(); msg.obj = choseAddressBean.name; msg.what = Stationed_List_Activity.NEW_ADDRESS; handler.sendMessage(msg); } }); if (position == 0) { viewHolder.iv_icon_chose.setVisibility(View.VISIBLE); icon = viewHolder.iv_icon_chose; } return convertView; } static class ViewHolder { private ImageView iv_icon_chose; private TextView tv_addressname_item; private RelativeLayout rl_icon_item; } }
出現(xiàn)圖片錯亂顯示的問題是因為快速翻動復(fù)用了View,那么每次將其重置即可。