2015-08-23 68 views
1

我正在開發一個音樂播放器應用程序。在列表視圖(音樂列表)中,我想添加播放點擊項目的均衡器圖像。但是,當我點擊它時,不可見項目也會顯示該圖像。如何處理它?Listview更改圖片點擊問題

 @Override 
     public void onItemClick(AdapterView<?> parent, View view, 
       int position, long id) { 
      p = position; 
      sound_id = MediaPlayerliClass.this.getResources() 
        .getIdentifier(parcalar.get(position), "raw", 
          MediaPlayerliClass.this.getPackageName()); 
      if (mp != null) { 
       mp.stop(); 
       mp.release(); 
       mp = null; 
      } 
      if (prevView != null) { 
       prevView.findViewById(R.id.simge).setBackgroundResource(0); 
      } 
      prevView = view; 

      mp = MediaPlayer.create(MediaPlayerliClass.this, sound_id); 
      mp.start(); 

      animation = new AnimationDrawable(); 
      animation.addFrame(getResources().getDrawable(R.drawable.equ1), 
        75); 
      animation.addFrame(getResources().getDrawable(R.drawable.equ2), 
        125); 
      animation.addFrame(getResources().getDrawable(R.drawable.equ3), 
        175); 

      animation.setOneShot(false); 
      text = (TextView) view.findViewById(R.id.isimsoyisim); 
      if(text.getText().toString()==parcalar.get(position)){    
      view.findViewById(R.id.simge) 
        .setBackgroundDrawable(animation); 
      } 

      // start the animation! 
      animation.start(); 
      view.findViewById(R.id.simge).setBackgroundDrawable(animation); 

回答

0

編輯:

@Override 
     public void onItemClick(AdapterView<?> parent, View view, 
       int position, long id) { 
      p = position; 
      sound_id = MediaPlayerliClass.this.getResources() 
        .getIdentifier(parcalar.get(position), "raw", 
          MediaPlayerliClass.this.getPackageName()); 
      if (mp != null) { 
       mp.stop(); 
       mp.release(); 
       mp = null; 
      } 
      if (prevView != null) { 
       prevView.findViewById(R.id.simge).setBackgroundResource(0); 
      } 
      prevView = view; 

      mp = MediaPlayer.create(MediaPlayerliClass.this, sound_id); 
      mp.start(); 

      animation = new AnimationDrawable(); 
      animation.addFrame(getResources().getDrawable(R.drawable.equ1), 
        75); 
      animation.addFrame(getResources().getDrawable(R.drawable.equ2), 
        125); 
      animation.addFrame(getResources().getDrawable(R.drawable.equ3), 
        175); 

      animation.setOneShot(false); 
      // start the animation! 
      animation.start(); 
      view.findViewById(R.id.simge).setBackgroundDrawable(animation);