listview item中点击按钮变化 滑动错乱

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
         final  SearchPlateModel searchPlateModel=searchPlateModels.get(position);
      if (convertView == null) {
         convertView = LayoutInflater.from(context).inflate(
               R.layout.plate_fund_item, null);
         viewHolder = new ViewHolder();
         viewHolder.name = (TextView) convertView
               .findViewById(R.id.fund_item_name);
         viewHolder.delete= (TextView) convertView.findViewById(R.id.fund_item_delete);
         viewHolder.add= (Button) convertView.findViewById(R.id.fund_item_add_btn);
  viewHolder.add.setTag(position);          convertView.setTag(viewHolder);

      } else {
         viewHolder = (ViewHolder) convertView.getTag();
         viewHolder.add.setTag(position);
      }
   viewHolder.name.setText(searchPlateModel.getFundName() + "(" + searchPlateModel.getFundCode() + ")");
//写在外面
   viewHolder.add.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
         searchPlateModel.setIsClick(true);
         notifyDataSetChanged();
         String urlstr_getInstID = "http://192.168.5.4/FundDataService/Pad/FundUserSection/SectionSampleInsert?logUser="+sAccount+"&sectionName="+sectionName+"&fundID="+searchPlateModel.getTransID();
         addSectionSampleTask = new HttpUtils.AddUserModels(urlstr_getInstID,handler, Constants.ACCEPT_TWO);
         addSectionSampleTask.execute((Void) null);
      }
   });

      if(searchPlateModels.get(position).getIsClick()==true){
         viewHolder.add.setClickable(false);
         viewHolder.add.setVisibility(View.GONE);
         viewHolder.delete.setText("已添加");
         viewHolder.delete.setVisibility(View.VISIBLE);
      }else{
         viewHolder.add.setText("添加");
         viewHolder.add.setClickable(true);
         viewHolder.add.setVisibility(View.VISIBLE);
         viewHolder.delete.setVisibility(View.GONE);

   }
   return convertView;

}

public class ViewHolder {
   private TextView name;
   private TextView delete;
   private Button add;
}

你可能感兴趣的:(listview item中点击按钮变化 滑动错乱)