0

我找不到问题,每当我滚动视图时都会改变。请帮助我...t认为android回收视图如何覆盖?

1.滚动 前 2.滚动后
滚动前 在此处输入图像描述

      public class MobileArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;
private LayoutInflater inflater;

public MobileArrayAdapter(Context context, String[] values) {
    super(context, R.layout.list_mobile, values);
      inflater = LayoutInflater.from(context);
    this.context = context;
    this.values = values;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View rowView=convertView;
    if (rowView == null) {

         rowView = inflater.inflate(R.layout.list_mobile, null);
         ViewHolder viewHolder = new ViewHolder();
         viewHolder.text = (TextView) rowView.findViewById(R.id.label);
                 viewHolder.button = (ImageView) rowView
             .findViewById(R.id.logo);

         rowView.setTag(viewHolder);
       }

       ViewHolder holder = (ViewHolder) rowView.getTag();
       String s = values[position];

       holder.text.setText(s);
               if (mp.isPlaying()) {
              holder.imageView.setImageResource(R.drawable.stop);
            } else {
              holder.imageView.setImageResource(R.drawable.play);
            }


    return rowView;
}static class ViewHolder {
       public TextView text;
       public ImageView button;

     }

}

在主要活动中

           protected void onListItemClick(ListView l, View v, int pos, long id) {





      if(mp.isPlaying() && itemno == pos){

         mp.pause();



         playing= true;

         ListMobileActivity.this. imageView.setImageResource(R.drawable.play);



      } 
      else if (playing=true && itemno== pos){
          mp.start();
          playing=false;


          ListMobileActivity.this.imageView.setImageResource(R.drawable.stop);
      }


      if (mp.isPlaying()&& itemno!=pos){
          ListMobileActivity.this.imageView.setImageResource(R.drawable.play);


      }

     if (itemno!=pos)
     {




          imageView = (ImageView)v. findViewWithTag(pos);




          playSample(pos);
        }            
      ListMobileActivity.this.itemno=pos;

        //Variable i, here, is from a for loop.



}

private void playSample( int position)
   {

           AssetFileDescriptor afd =  getApplicationContext().getResources().openRawResourceFd(songs[position]);


           try{
               if(mp.isPlaying())


              ListMobileActivity.  this.mp.stop();






            ListMobileActivity.    this.mp.reset();
            ListMobileActivity.    this.mp.setDataSource(afd.getFileDescriptor(),           afd.getStartOffset(), afd.getDeclaredLength());
            ListMobileActivity.    this.mp.prepare();

 ListMobileActivity. this. imageView.setImageResource(R.drawable.stop);


      ListMobileActivity.this.    mp.setOnCompletionListener(new OnCompletionListener() {

              public void onCompletion(MediaPlayer mp) {

                    ListMobileActivity. this.    imageView.setImageResource(R.drawable.play);


              }


              });

      ListMobileActivity.   this.   mp.start();

                afd.close();



        }
        catch (IllegalArgumentException e)
        {
            Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e);
        }
        catch (IllegalStateException e)
        {
            Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e);
        }
        catch (IOException e)
        {
            Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e);
        }
}
4

2 回答 2

0

我认为您正在使用自定义布局来查看列表项。

所以现在发生的事情是,当您使用自定义布局时,它将使布局膨胀,并将再次用于下一个项目。

在自定义适配器的获取视图中检查条件与此类似。

if(Song2.isplaying)
{
   imgView.setImage(pauseimage);
}
else
{
   imgView.setImage(playimage);
}

它会为你工作。

(它只是代码逻辑表示,因此需要您设置检查标准。)

于 2013-07-23T08:41:12.847 回答
0

1.这里你正在使用array[]列表视图显示,你也尝试显示ImageView

String s = values[position];
holder.text.setText(s);

2.所以首先检查setImage的值

 if (s.startsWith("al")) {
      holder.image.setImageResource(R.drawable.baloon);
    } else {
      holder.image.setImageResource(R.drawable.pause);
    }

3.否则你应该做一个客户适配器

于 2013-07-23T08:52:24.637 回答