滚动

时间:2017-06-21 12:19:16

标签: android listview

我有一个android自定义列表视图。

但是当我的listview滚动一些项目重复!!!!
我的自定义列表视图代码是:

 static class ViewHolder {
    ImageView imgPlaySound,imgShareList;
    TextView txtCaption,txtDynamicTimer,txtDurationSplit,txtTotalTimer,txtHiden;
    Spinner spTags;
    SeekBar soundSeekBar;
    LinearLayout linearSeek;
    int positions;
}

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

    vg = parent;
    final ArrayList arrTagNameTemp = new ArrayList();
    final ArrayList arrStartTimeTemp = new ArrayList();
    final ArrayList arrStopTimeTemp = new ArrayList();

    arrTagNameTemp.add("all");
    final ViewHolder viewHolder;
    if (convertView == null) {
        LayoutInflater inflater = context.getLayoutInflater();
        convertView = inflater.inflate(R.layout.listview, null);
        viewHolder = new ViewHolder();
        viewHolder.positions = position;
        viewHolder.txtCaption = (TextView) convertView.findViewById(R.id.txtCaption);
        viewHolder.txtDynamicTimer  = (TextView) convertView.findViewById(R.id.txtDynamicTimer);
        viewHolder.txtDurationSplit = (TextView) convertView.findViewById(R.id.txtTotalTimer);
        viewHolder.imgPlaySound = (ImageView) convertView.findViewById(R.id.imgPlaySound);
        viewHolder.imgShareList = (ImageView) convertView.findViewById(R.id.imgShareList);
        viewHolder.linearSeek = (LinearLayout) convertView.findViewById(R.id.linearSeek);
        viewHolder.soundSeekBar = (SeekBar) convertView.findViewById(R.id.seekBar1);
        viewHolder.spTags = (Spinner) convertView.findViewById(R.id.spTags);
       // viewHolder.imgPlaySound.setOnClickListener(vdClickListener);
        convertView.setTag(viewHolder);
    }
    else
    {
        viewHolder = (ViewHolder) convertView.getTag();
    }
   /////////////////////////////////////////////////////////////////////////
    final MenuItem strListItem = (MenuItem) arrSubject.get(position);
    //viewHolder.txtCaption.setText(arrSubject.get(viewHolder.positions).toString());
    viewHolder.txtCaption.setText(strListItem.getItemId());
    return convertView;
}


我很困惑。
有人可以帮我解决这个问题吗?

2 个答案:

答案 0 :(得分:0)

final ArrayList arrTagNameTemp = new ArrayList();
final ArrayList arrStartTimeTemp = new ArrayList();
final ArrayList arrStopTimeTemp = new ArrayList();    

static class ViewHolder {
     ImageView imgPlaySound,imgShareList;
     TextView txtCaption,txtDynamicTimer,txtDurationSplit,txtTotalTimer,txtHiden;
     Spinner spTags;
     SeekBar soundSeekBar;
     LinearLayout linearSeek;
     int positions;
}

  @Override
  public View getView(final int position,View convertView, final ViewGroup parent) {
ViewHolder viewHolder=new ViewHolder();
if (convertView == null) {
    LayoutInflater inflater = context.getLayoutInflater();
    convertView = inflater.inflate(R.layout.listview, null);
    viewHolder.txtCaption = (TextView) convertView.findViewById(R.id.txtCaption);
    viewHolder.txtDynamicTimer  = (TextView) convertView.findViewById(R.id.txtDynamicTimer);
    viewHolder.txtDurationSplit = (TextView) convertView.findViewById(R.id.txtTotalTimer);
    viewHolder.imgPlaySound = (ImageView) convertView.findViewById(R.id.imgPlaySound);
    viewHolder.imgShareList = (ImageView) convertView.findViewById(R.id.imgShareList);
    viewHolder.linearSeek = (LinearLayout) convertView.findViewById(R.id.linearSeek);
    viewHolder.soundSeekBar = (SeekBar) convertView.findViewById(R.id.seekBar1);
    viewHolder.spTags = (Spinner) convertView.findViewById(R.id.spTags);
   // viewHolder.imgPlaySound.setOnClickListener(vdClickListener);
    convertView.setTag(viewHolder);
}else{
    viewHolder = (ViewHolder) convertView.getTag();
}

final MenuItem strListItem = (MenuItem) arrSubject.get(position);
viewHolder.txtCaption.setText(strListItem.getItemId());
return convertView;
}

答案 1 :(得分:0)

  

尝试使用演示结构,只需添加布局和Pass上下文以及PoJo类。这只是演示

public class MoveinAdapter extends BaseAdapter {

    private ArrayList<MoveinResponse> MoveinResponse;
    private Context cntx;
    private ViewHolder holder;
    private View convertView;

    public MoveinAdapter(Context cntx, ArrayList<MoveinResponse> MoveinResponse) {
        // TODO Auto-generated constructor stub

        this.MoveinResponse = MoveinResponse;
        this.cntx = cntx;
        holder = null;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return MoveinResponse.size();
    }

    @Override
    public Object getItem(int position) {
        return MoveinResponse.get(position);
    }

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

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) cntx
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.row_movein_screen, parent, false);
            holder = new ViewHolder();
            holder.row_movein_customer = (TextView) convertView
                    .findViewById(R.id.row_movein_customer);

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

        final MoveinResponse nevi = MoveinResponse.get(position);
        holder.row_movein_customer.setText(nevi.getCustomerName());

        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                 Toast.makeText(cntx,"Here your clicked view",Toast.LENGTH_SHORT).show();
            }
        });
        return convertView;
    } 
    private static class ViewHolder {
        public TextView row_movein_customer;

    }
}