@Override
 public View getView(int i, View view, ViewGroup viewGroup) {
   ViewHolder viewHolder = null;
   if (view == null) {
     view = LayoutInflater.from(context).inflate(R.layout.contacts_item, null);
     viewHolder = new ViewHolder();
     viewHolder.name = (TextView) view.findViewById(R.id.name);
     viewHolder.number = (TextView) view.findViewById(R.id.number);
     viewHolder.check = (CheckBox) view.findViewById(R.id.check);
     view.setTag(viewHolder);
   } else viewHolder = (ViewHolder) view.getTag();
   viewHolder.name.setText(list.get(i).getName());
   viewHolder.number.setText(list.get(i).getPhonenumber());
   viewHolder.check.setOnCheckedChangeListener(
       new CompoundButton.OnCheckedChangeListener() {
         @Override
         public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
           if (isChecked) {
             mCBFlag.put(i, true);
           } else {
             mCBFlag.put(i, false);
           }
         }
       });
   /*CheckBox监听事件必须放在setChecked之前,否则后果自负*/
   viewHolder.check.setChecked(mCBFlag.get(i));
   Log.d("position:", "i=" + i + ",view=" + view);
   return view;
 }
示例#2
0
  private ViewHolder getViewHolder(final View workingView) {
    final Object tag = workingView.getTag();
    ViewHolder viewHolder = null;

    if (null == tag || !(tag instanceof ViewHolder)) {
      viewHolder = new ViewHolder();

      viewHolder.nameView = (TextView) workingView.findViewById(R.id.name);
      viewHolder.dateView = (TextView) workingView.findViewById(R.id.date);
      viewHolder.sizeView = (TextView) workingView.findViewById(R.id.size);
      viewHolder.imageView = (ImageView) workingView.findViewById(R.id.image);

      workingView.setTag(viewHolder);

    } else {
      viewHolder = (ViewHolder) tag;
    }

    return viewHolder;
  }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder holder;
      if (convertView == null) {
        holder = new ViewHolder();
        convertView = LayoutInflater.from(getActivity()).inflate(R.layout.item_song, null);
        holder.mTvName = (TextView) convertView.findViewById(R.id.tv_name);
        holder.mTvArtist = (TextView) convertView.findViewById(R.id.tv_artist);
        holder.mTvDuration = (TextView) convertView.findViewById(R.id.tv_duration);
        holder.aboveView = convertView.findViewById(R.id.item_root);
        holder.behindView = convertView.findViewById(R.id.behind);
        convertView.setTag(holder);
        convertViewList.add((PullRightLayout) convertView);
      } else {
        holder = (ViewHolder) convertView.getTag();
      }
      if (HideApplication.showListAnim) {
        startAnim(convertView);
      }

      SongInfo info = SongManager.with(getActivity()).getSongByIndex(position);
      holder.mTvName.setText(info.getTitle());
      holder.mTvArtist.setText(info.getArtist() + " - " + info.getAlbum());
      holder.mTvDuration.setText(
          CommonUtils.durationToString(info.getDuration())
              + " - "
              + CommonUtils.getFileSize(info.getPath()));

      setItemSelected(holder, info.getId() == playingId);

      convertView.setOnClickListener(new OnItemClick(position));
      holder.behindView.setOnClickListener(new OnBehindClick(position));

      return convertView;
    }
  @Override
  public View getView(int position, View convertViewIn, ViewGroup parent) {
    View convertView = convertViewIn;
    ViewHolder holder;
    if (convertView == null) {
      convertView = inflater.inflate(R.layout.filter_channel_element, null);
      holder = new ViewHolder();
      holder.iconeChaine =
          (ImageView) convertView.findViewById(R.id.filter_channel_element_imageChaine);
      holder.displayName =
          (TextView) convertView.findViewById(R.id.filter_channel_element_displayName);
      holder.favorite = (CheckBox) convertView.findViewById(R.id.filter_channel_element_favorite);
      convertView.setTag(holder);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }

    Channel channel = getItem(position);

    holder.displayName.setText(channel.getDisplayName());
    holder.iconeChaine.setImageResource(channel.getIconResource());
    holder.favorite.setChecked(channel.isFavorite());
    return convertView;
  }
  @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
    final PackageItem item = getItem(position);
    ViewHolder holder;
    if (convertView == null) {
      LayoutInflater li =
          (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      convertView = li.inflate(R.layout.package_row, parent, false);
      holder = new ViewHolder();
      holder.tvTitle = (TextView) convertView.findViewById(R.id.example_row_tv_title);
      holder.tvDescription = (TextView) convertView.findViewById(R.id.example_row_tv_description);
      holder.bAction1 = (ImageButton) convertView.findViewById(R.id.button_edit_rule);
      holder.bAction2 = (Button) convertView.findViewById(R.id.button_disable_rule);
      holder.bAction3 = (ImageButton) convertView.findViewById(R.id.button_delete_rule);
      convertView.setTag(holder);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }

    ((SwipeListView) parent).recycle(convertView, position);

    holder.tvTitle.setText(item.getName());
    holder.tvDescription.setText(item.toString());

    holder.bAction1.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            mHandler.obtainMessage(RuleList.MESSAGE_EDIT_RULE, position, -1).sendToTarget();
          }
        });

    holder.bAction2.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            mHandler.obtainMessage(RuleList.MESSAGE_DISABLE_RULE, position, -1).sendToTarget();
          }
        });

    holder.bAction3.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            mHandler.obtainMessage(RuleList.MESSAGE_DELETE_RULE, position, -1).sendToTarget();
          }
        });

    return convertView;
  }
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

      final ViewHolder holder;

      if (convertView == null) {

        convertView = m_Inflater.inflate(R.layout.reputation_item, parent, false);

        holder = new ViewHolder();

        holder.txtIsNew = (ImageView) convertView.findViewById(R.id.txtIsNew);
        holder.txtAuthor = (TextView) convertView.findViewById(R.id.txtAuthor);
        holder.txtAuthor.setTextSize(m_TopTextSize);

        holder.txtLastMessageDate = (TextView) convertView.findViewById(R.id.txtLastMessageDate);
        holder.txtLastMessageDate.setTextSize(m_TopTextSize);

        holder.txtTitle = (TextView) convertView.findViewById(R.id.txtTitle);
        holder.txtTitle.setTextSize(m_ThemeTitleSize);

        holder.txtForumTitle = (TextView) convertView.findViewById(R.id.txtForumTitle);

        holder.txtForumTitle.setTextSize(m_BottomTextSize);

        convertView.setTag(holder);
      } else {
        holder = (ViewHolder) convertView.getTag();
      }

      Reputation rep = this.getItem(position);

      holder.txtAuthor.setText(rep.user);
      holder.txtLastMessageDate.setText(rep.date);
      holder.txtTitle.setText(rep.description);

      holder.txtForumTitle.setText("@" + rep.source);

      if (rep.level.equals("up")) {
        holder.txtIsNew.setImageResource(R.drawable.new_flag);
      } else {
        holder.txtIsNew.setImageResource(R.drawable.old_flag);
      }

      return convertView;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder holder = null;
      if (convertView == null) {
        holder = new ViewHolder();
        convertView = getLayoutInflater().inflate(R.layout.listitem_lesson_status, parent, false);
        holder.tv_per = (TextView) convertView.findViewById(R.id.item_les_perform_tv);
        holder.rg_per = (RadioGroup) convertView.findViewById(R.id.item_les_radioGroup);
        holder.radio0 = (RadioButton) convertView.findViewById(R.id.radio0);
        holder.radio1 = (RadioButton) convertView.findViewById(R.id.radio1);
        holder.radio2 = (RadioButton) convertView.findViewById(R.id.radio2);
        convertView.setTag(holder);
      } else {
        holder = (ViewHolder) convertView.getTag();
      }
      holder.tv_per.setText(pers[position]);
      if (!stuPersFromNet.isEmpty()) {
        if (stuPersFromNet.get(0).property_id == 10) {
          if (!isTeacher) {
            holder.radio0.setChecked(false);
            holder.radio1.setChecked(false);
            holder.radio2.setChecked(false);
          }
          final LessonPerformance performance = new LessonPerformance();
          performance.property_value = 1;
          performance.lesson_id = lessonId;
          performance.student_id = stuId;
          performance.property_id = position + 1;
          holder.rg_per.setOnCheckedChangeListener(
              new RadioGroup.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(RadioGroup group, int checkedId) {
                  switch (checkedId) {
                    case R.id.radio0:
                      performance.property_value = 1;
                      break;
                    case R.id.radio1:
                      performance.property_value = 2;
                      break;
                    case R.id.radio2:
                      performance.property_value = 3;
                      break;
                    default:
                      performance.property_value = 1;
                      break;
                  }
                }
              });
          lesPersToPost.add(performance);
        } else {
          if (position < stuPersFromNet.size()) {
            int value = stuPersFromNet.get(position).property_value;
            switch (value) {
              case 1:
                holder.radio0.setChecked(true);
                break;
              case 2:
                holder.radio1.setChecked(true);
                break;
              case 3:
                holder.radio2.setChecked(true);
                break;
            }
          }
          holder.rg_per.setEnabled(false);
          holder.radio0.setEnabled(false);
          holder.radio1.setEnabled(false);
          holder.radio2.setEnabled(false);
        }

      } else {
        if (!isTeacher) {
          holder.radio0.setChecked(false);
          holder.radio1.setChecked(false);
          holder.radio2.setChecked(false);
        }
        final LessonPerformance performance = new LessonPerformance();
        performance.property_value = 1;
        performance.lesson_id = lessonId;
        performance.student_id = stuId;
        performance.property_id = position + 1;
        holder.rg_per.setOnCheckedChangeListener(
            new RadioGroup.OnCheckedChangeListener() {

              @Override
              public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                  case R.id.radio0:
                    performance.property_value = 1;
                    break;
                  case R.id.radio1:
                    performance.property_value = 2;
                    break;
                  case R.id.radio2:
                    performance.property_value = 3;
                    break;
                  default:
                    performance.property_value = 1;
                    break;
                }
              }
            });
        lesPersToPost.add(performance);
      }
      if (!isTeacher) {
        holder.rg_per.setEnabled(false);
        holder.radio0.setEnabled(false);
        holder.radio1.setEnabled(false);
        holder.radio2.setEnabled(false);
      }
      return convertView;
    }