ListView多选滚动问题

ListView中当选择一行或多行变色后,滚动列表后出现选中行发生了变化,在项目中遇到了这样的问题,记录下来。

public class MyListAdapter extends BaseAdapter {
		LayoutInflater layoutInflater;
		
		public MyListAdapter(Context c) {
			this.layoutInflater = LayoutInflater.from(c);
		}

		public int getCount() {
			return jsonArray.size();
		}

		public Object getItem(int position) {
			return jsonArray.get(position);
		}

		public long getItemId(int position) {
			return position;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
        	ViewHolder viewHolder = null;
        	if(convertView == null){
        		viewHolder = new ViewHolder();
        		convertView = layoutInflater.inflate(R.layout.activity_undone_site_item, null);
        		viewHolder.siteText = (TextView) convertView.findViewById(R.id.site_name);
        		convertView.setTag(viewHolder);
        	}else{
        		viewHolder = (ViewHolder) convertView.getTag();
        	}
        	
        	//从集合中获取数据
        	final JSONObject jsonObject = (JSONObject) jsonArray.get(position);
        	final ViewHolder mViewHolder = viewHolder;
        	String textName = jsonObject.get("NAME").toString();
        	viewHolder.siteText.setText(textName);
        	//下载
    		viewHolder.siteDownload.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View view) {
					jsonObject.put("status", "1");
					mViewHolder.siteText.setBackgroundDrawable(getResources().getDrawable(drawable.grid_view_exist_bg));
					//刷新ListView
					MyListAdapter.this.notifyDataSetChanged(); 
				}
			});
    		
    		String status = jsonObject.get("status")!=null ? jsonObject.get("status").toString() : "";
    		if("1".equals(status)){
    			viewHolder.siteText.setBackgroundDrawable(getResources().getDrawable(drawable.grid_view_exist_bg));
    		}else{
    			viewHolder.siteText.setBackgroundDrawable(getResources().getDrawable(drawable.grid_view_btn_bg));
    		}
    		
			return convertView;
		}
	}
相关文章
相关标签/搜索