如何在listview上更改图像

时间:2016-02-06 15:52:57

标签: android listview

当我点击从列表视图更改图像时出现问题:我只需要在行中更改图像即可。当我选择另一张图像时,我选择的这张图像会变成图像正常。请帮帮我!

MainActivity

public void songPicked(final View view) throws IOException {
        musicSrv.setSong(Integer.parseInt(view.getTag().toString()));
        ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
        imageView.setImageResource(R.drawable.playc);
        musicSrv.playSong();
        if (playbackPaused) {
            setController();
            playbackPaused = false;
        }
        controller.show(0);
    } 

MyAdapter

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

        //map to song layout
        RelativeLayout songLay = (RelativeLayout) songInf.inflate
                (R.layout.song, parent, false);
        //get title and artist views
        TextView songView = (TextView) songLay.findViewById(R.id.song_title);
        TextView artistView = (TextView) songLay.findViewById(R.id.song_artist);
        final ImageView imageView= (ImageView) songLay.findViewById(R.id.imageView);
        //get song using position
        Song currSong = songs.get(position);

        //get title and artist strings
        songView.setText(currSong.getTitle());
        artistView.setText(currSong.getArtist());
        imageView.setImageDrawable(
                    getContext().getDrawable(R.drawable.play));


        //set position as tag
        songLay.setTag(position);
        return songLay;
    }

http://i.stack.imgur.com/ZWGlN.jpg

0 个答案:

没有答案