Listview更改图像时单击问题

时间:2015-08-23 14:07:56

标签: listview

我正在开发一款音乐播放器应用。在listview(音乐列表)中,我想添加点击项目的播放均衡器图像。但是,当我点击它时,不可见的项目也有该图像。我该如何处理它?<​​/ p>

        @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);

1 个答案:

答案 0 :(得分: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);