2016-12-23 148 views
0

我有一个复选框的列表视图,其中第一个复选框被选中,在页脚我有下一个按钮,如果用户点击下一个按钮,然后下一个复选框是检查第二行被选中。如果再按next,则检查第三个。请帮助我被困在那么久。谢谢。复选框检查按钮点击

public class PlanetArrayAdapter extends ArrayAdapter<Planet> { 

    private LayoutInflater inflater; 
    ArrayList<Boolean> positionArray; 
    Context ctx; 

    public PlanetArrayAdapter(Context context, List<Planet> planetList) { 
     super(context, R.layout.list_rowss, R.id.rowTextView, planetList); 
     // Cache the LayoutInflate to avoid asking for a new one each time. 
     inflater = LayoutInflater.from(context) ; 
     positionArray = new ArrayList<Boolean>(planetList.size()); 
     for(int i =0;i<planetList.size();i++){ 
      positionArray.add(false); 
     } 
    } 

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

     position_new =position; 
     Planet planet = (Planet) this.getItem(position_new);  
     final CheckBox checkBox ; 
     final TextView textView,textview_duration_MAX, textview_duration_Current; 
     final CheckBox pauseplay; ; 

     final ImageView download,fb,twitter,add; 
     final SeekBar pb; 

     if (convertView == null) { 
      convertView = inflater.inflate(R.layout.list_rowss, null); 


      textView = (TextView) convertView.findViewById(R.id.rowTextView); 

      checkBox = (CheckBox) convertView.findViewById(R.id.CheckBox01); 
      pb = (SeekBar) convertView.findViewById(R.id.songProgressBar); 
      pauseplay = (CheckBox)convertView.findViewById(R.id.button); 
      textview_duration_MAX = (TextView)convertView.findViewById(R.id.textView3); 
      textview_duration_Current =(TextView)convertView.findViewById(R.id.textView2); 
      download = (ImageView) convertView.findViewById(R.id.imageView); 
      fb = (ImageView) convertView.findViewById(R.id.imageView4); 
      twitter = (ImageView) convertView.findViewById(R.id.imageView5); 
      add = (ImageView) convertView.findViewById(R.id.imageView6); 

      checkBox.setTag(position); 

      // Optimization: Tag the row with it's child views, so we don't have to 
      // call findViewById() later when we reuse the row. 
      convertView.setTag(new PlanetViewHolder(textView,textview_duration_MAX,textview_duration_Current,checkBox,pb,pauseplay,add)); 



      checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
       @Override 
       public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 

        Planet palnts = (Planet) buttonView.getTag(); 


        Log.d("poiuy",palnts+"");//For getting checkbox postion 


        CheckBox cb = (CheckBox) buttonView; 

        Planet planet = (Planet) cb.getTag(); 
        planet.setChecked(cb.isChecked()); 

        boolean isStart; 

        if (checkBox.isChecked()) { 


         if (selected != null) { 
          selected.setChecked(false); 
         } 

         checkBox.setChecked(true); 
         selected = checkBox; 

         pauseplay.setVisibility(View.VISIBLE); 
         song_namef.setText(planet.getName().substring(18)); 
         playButton.setImageResource(R.drawable.pausef); 

         View parentRow = (View) buttonView.getParent(); 
         ListView listView = (ListView) parentRow.getParent(); 
         positiono = listView.getPositionForView(parentRow); 
         mPlayingPosition = positiono; 

         final Runnable mUpdateTime = new Runnable() { 
          public void run() { 
           int currentDuration; 
           int totalduration; 
           if (mPlayer.isPlaying()) { 
            currentDuration = mPlayer.getCurrentPosition(); 
            totalduration = mPlayer.getDuration(); 
            textview_duration_MAX.setText("" + milliSecondsToTimer((long) totalduration)); 
            textview_duration_Current.setText("" + milliSecondsToTimer((long) currentDuration)); 
            textview_duration_Current.postDelayed(this, 1000); 
           } else { 
            textview_duration_Current.removeCallbacks(this); 
           } 
          } 
         }; 

         isStart = false; 
         // Toast.makeText(getContext(), "Play", Toast.LENGTH_SHORT).show(); 
         Toast.makeText(getContext(),"positiono"+positiono,Toast.LENGTH_SHORT).show(); 
         Log.d("OnlyPosssssd", String.valueOf(mPlayingPosition)); 


         try { 
          mPlayer.reset(); 
          mPlayer.setDataSource(String.valueOf(planet = listAdapter.getItem(mPlayingPosition))); 

          mPlayer.prepare(); 
          mPlayer.start(); 
          mPlayingPosition = positiono; 
          // Log.d("OnlyPos", String.valueOf(mPlayingPosition)); 


          pb.setProgress(0); 
          pb.setMax(100); 


          seekbarf.setMax(mPlayer.getDuration()); 

          updatePosition(); 

          isStarted = true; 
          mHandler.postDelayed(mProgressUpdater, 500); 

         } catch (IOException e) { 

          e.printStackTrace(); 

         } 
        );} 


      next.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 
        Toast.makeText(getContext(),"Next",Toast.LENGTH_SHORT).show(); 
        itemPosition = itemPosition+1; 
        next(itemPosition); 
        playSong(itemPosition); 
        if (view != null) { 
         CheckBox checkBox = (CheckBox)view.findViewById(R.id.CheckBox01); 
         checkBox.setChecked(!checkBox.isChecked()); 

        } 
       } 
      }); 

    public void next(int next){ 

    Toast.makeText(getContext(),"Position :"+itemPosition+" ListItem : " +itemValue , Toast.LENGTH_LONG).show(); 
next, Toast.LENGTH_SHORT).show(); 

    parents.getChildAt(next).setBackground(getContext().getDrawable(R.drawable.backpause)); 

    if (save != -1 && save != next){ 
     parents.getChildAt(save).setBackgroundColor(Color.TRANSPARENT);  
    } 
    save = next; 

} 
+0

你可以发布你的代码吗? –

+0

我们会帮助你,但你必须显示你做了什么,什么不工作:) –

+0

没有代码? – Piyush

回答

0

正如你在你的星球类setChecked方法已经,最好是你把最后点击指标的跟踪和每单击下一步按钮,增加它。然后根据getChecked()结果从该索引处的项目列表中获取星球项目,setChecked(true)或false,然后调用adapter.notifydatasetchanged。

+0

请@Rajen帮助一些代码 –

+0

你在哪里定义了接下来的方法(itemPosition);?在返回视图下面的 –

+0

。 –