2017-06-24 83 views
0

我有一個自定義的ListView 微調ListArray填寫。
它工作正常,沒有的ListView滾動

但當我增加一些項目,我的定製的ListView,我選擇在我的微調第一或第二的一個項目,我向下滾動我的ListView (直到該行消失)我看到底部項目的另一個微調將選擇(如上)
我的選擇保持,但另一微調在底部的ListView是選擇

我的代碼是:
Android的ListView控件微調時滾動

public class SoundListView extends ArrayAdapter<String>{ 
     List<String> DataList; 
     private final Activity context; 
     private ViewGroup vg; 
     int startTimer, stopTimer,rPosition; 
     String fileTagName = "",externalTagFileName = "",tagFileName= "",fileName = ""; 

     public SoundListView (Activity context, ArrayList arrSubject, ArrayList arrDurationSplit, ArrayList ids,ArrayList arrFileName,ArrayList arrDuration,ArrayList arrIdTag,ArrayList arrTagName,ArrayList arrMainId,ArrayList arrStartTime, ArrayList arrStopTime) { 
      super(context, R.layout.activity_list, arrSubject); 
      this.context = context; 
      this.arrSubject = arrSubject; 
      this.arrDurationSplit = arrDurationSplit; 
      this.arrIdTag = arrIdTag; 
      this.arrDuration = arrDuration; 
      this.arrTagName = arrTagName; 
      this.arrMainId = arrMainId; 
      this.arrStartTime = arrStartTime; 
      this.arrStopTime = arrStopTime; 
      this.arrFileName = arrFileName; 
      this.ids = ids; 
     } 
     private ArrayList arrSubject = new ArrayList(); 
     private ArrayList arrDurationSplit = new ArrayList(); 
     private ArrayList ids = new ArrayList(); 
     private ArrayList arrIdTag = new ArrayList(); 
     private ArrayList arrTagName = new ArrayList(); 
     private ArrayList arrMainId = new ArrayList(); 
     private ArrayList arrStartTime = new ArrayList(); 
     private ArrayList arrStopTime = new ArrayList(); 
     private ArrayList arrDuration = new ArrayList(); 
     private ArrayList arrFileName = new ArrayList(); 
     final private ArrayList<String> arrayTasPath = new ArrayList<String>(); 

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

     @Override 
     public View getView(final int position,View convertView, final ViewGroup parent) { 
      LayoutInflater inflater = context.getLayoutInflater(); 
      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) { 
       convertView = inflater.inflate(R.layout.listview, null); 
       viewHolder = new ViewHolder(); 
       viewHolder.position = 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.spTags = (Spinner) convertView.findViewById(R.id.spTags); 
       final ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,android.R.layout.simple_spinner_item, arrTagNameTemp); 
       viewHolder.spTags.setAdapter(adapter); 
       viewHolder.spTags.setSelection(0); 
       final int duration = Integer.valueOf(arrDuration.get(position).toString()); 
       for(int i = 0; i < arrMainId.size(); i++) 
       { 
        if (Integer.valueOf(arrMainId.get(i).toString()) == Integer.valueOf(ids.get(position).toString())) 
        { 
         arrTagNameTemp.add(arrTagName.get(i)); 
         arrStartTimeTemp.add(arrStartTime.get(i)); 
         arrStopTimeTemp.add(arrStopTime.get(i)); 
        } 
       } 
       ////////////////////////////////////////////////////////////////////////////// 
       convertView.setTag(viewHolder); 
      } 
      else 
      { 
       viewHolder = (ViewHolder) convertView.getTag(); 
      } 
      viewHolder.txtCaption.setText(arrSubject.get(position).toString()); 
      return convertView; 
     } 


任何人可以幫助我嗎?

回答

0

首先告訴我爲什麼你使用那麼多的數組列表,你不能只用一個自定義數據類型。在單個數組中,所有值都將相互關聯,並且易於管理它們。

我提出的問題的解決方案是創建一個具有自定義數據類型的ArrayList,包括上面給出的所有ArrayList的所有值。並且不要在適配器中初始化您的陣列。初始化並在您設置Adapter的位置添加值(在您的活動中)。你必須在主數組中添加一個參數,比如說「selectedValue」,默認情況下它會是「all」,但是當用戶選擇某個值時,你將更新該特定位置上的項目值。

然後在您的getView方法中,您將檢查每個項目的「selectedValue」的值,如果它等於「all」,那麼您將設置它,否則,您將爲您的微調器設置「selectedValue」的值。只要記住一點,你必須爲if和else子句中的每個項目的微調器設置一個值。