• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Cant update a single row in listview

Hello every body, i'm new to android and i'm creating a mp3 app where there will be a list of all the mp3s and two buttons. "play" and "download" button.

The problem i'm facing is that when ever i'm clicking on any of the play button, the music starts and the button changes from play to pause.

but when i'm clicking on any other list, the same happens but the previous play button should change to "play" button which I cant make it work.

Below i'm sharing my code.

Code:
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {

        if(convertView == null)
        {
            LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.songs_list,null,true);
        }

        final Songs songs = getItem(position);

        TextView songs_name = (TextView) convertView.findViewById(R.id.songs_name);
        songs_name.setText(songs.getName());

        final ImageButton listPlayBtn = (ImageButton) convertView.findViewById(R.id.listPlayBtn);

        final Integer play = 0;
        listPlayBtn.setOnClickListener(new View.OnClickListener() {
            String song_name = songs.getName();
            String song_url = songs.getUrl();
            Integer play1 = play;

            @Override
            public void onClick(View v) {
                MucisPlayer mp = new MucisPlayer();
                if(play1 == 0) {
                    mp.play1(song_url, song_name, mediaplayer);
                    play1 = 1;
                    System.out.println("Play");
                    listPlayBtn.setImageResource(R.drawable.pause);
                }
                else
                {
                    mp.pause(mediaplayer);
                    play1 = 0;
                    System.out.println("Pause");
                    listPlayBtn.setImageResource(R.drawable.play);
                }
            }
        });

        final ImageButton listDownloadBtn = (ImageButton) convertView.findViewById(R.id.listDownloadBtn);

        listDownloadBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String song_name = songs.getName();
                String song_url = songs.getUrl();
                System.out.println("Download Clicked");
                Album_details ad = new Album_details();
                ad.downloadFileFromNet(song_url,song_name);
            }
        });
        return convertView;
    }

0PEY0tT.png


Any help will be appreciated. Thank you in advance..
 
Hello every body, i'm new to android and i'm creating a mp3 app where there will be a list of all the mp3s and two buttons. "play" and "download" button.

The problem i'm facing is that when ever i'm clicking on any of the play button, the music starts and the button changes from play to pause.

but when i'm clicking on any other list, the same happens but the previous play button should change to "play" button which I cant make it work.

Below i'm sharing my code.

Code:
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {

        if(convertView == null)
        {
            LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.songs_list,null,true);
        }

        final Songs songs = getItem(position);

        TextView songs_name = (TextView) convertView.findViewById(R.id.songs_name);
        songs_name.setText(songs.getName());

        final ImageButton listPlayBtn = (ImageButton) convertView.findViewById(R.id.listPlayBtn);

        final Integer play = 0;
        listPlayBtn.setOnClickListener(new View.OnClickListener() {
            String song_name = songs.getName();
            String song_url = songs.getUrl();
            Integer play1 = play;

            @Override
            public void onClick(View v) {
                MucisPlayer mp = new MucisPlayer();
                if(play1 == 0) {
                    mp.play1(song_url, song_name, mediaplayer);
                    play1 = 1;
                    System.out.println("Play");
                    listPlayBtn.setImageResource(R.drawable.pause);
                }
                else
                {
                    mp.pause(mediaplayer);
                    play1 = 0;
                    System.out.println("Pause");
                    listPlayBtn.setImageResource(R.drawable.play);
                }
            }
        });

        final ImageButton listDownloadBtn = (ImageButton) convertView.findViewById(R.id.listDownloadBtn);

        listDownloadBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String song_name = songs.getName();
                String song_url = songs.getUrl();
                System.out.println("Download Clicked");
                Album_details ad = new Album_details();
                ad.downloadFileFromNet(song_url,song_name);
            }
        });
        return convertView;
    }

0PEY0tT.png


Any help will be appreciated. Thank you in advance..
Hello every body, i'm new to android and i'm creating a mp3 app where there will be a list of all the mp3s and two buttons. "play" and "download" button.

The problem i'm facing is that when ever i'm clicking on any of the play button, the music starts and the button changes from play to pause.

but when i'm clicking on any other list, the same happens but the previous play button should change to "play" button which I cant make it work.

Below i'm sharing my code.

Code:
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {

        if(convertView == null)
        {
            LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.songs_list,null,true);
        }

        final Songs songs = getItem(position);

        TextView songs_name = (TextView) convertView.findViewById(R.id.songs_name);
        songs_name.setText(songs.getName());

        final ImageButton listPlayBtn = (ImageButton) convertView.findViewById(R.id.listPlayBtn);

        final Integer play = 0;
        listPlayBtn.setOnClickListener(new View.OnClickListener() {
            String song_name = songs.getName();
            String song_url = songs.getUrl();
            Integer play1 = play;

            @Override
            public void onClick(View v) {
                MucisPlayer mp = new MucisPlayer();
                if(play1 == 0) {
                    mp.play1(song_url, song_name, mediaplayer);
                    play1 = 1;
                    System.out.println("Play");
                    listPlayBtn.setImageResource(R.drawable.pause);
                }
                else
                {
                    mp.pause(mediaplayer);
                    play1 = 0;
                    System.out.println("Pause");
                    listPlayBtn.setImageResource(R.drawable.play);
                }
            }
        });

        final ImageButton listDownloadBtn = (ImageButton) convertView.findViewById(R.id.listDownloadBtn);

        listDownloadBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String song_name = songs.getName();
                String song_url = songs.getUrl();
                System.out.println("Download Clicked");
                Album_details ad = new Album_details();
                ad.downloadFileFromNet(song_url,song_name);
            }
        });
        return convertView;
    }

0PEY0tT.png


Any help will be appreciated. Thank you in advance..

Hi,
You need to write if condition on button click and then check whether the songs is being played or not and then if not being played then action is to be performed

This way you will avoid playing multiple tracks at once.

A simple solution may be useful for u make a boolean variable and check whether if it is true then play or else not

From
abhi
 
Last edited by a moderator:
Thank you for your reply but I think you have not read my question. The music is played as usual. There is no problem with the music player. only the button is not going back to previous state.

let me give an example,

there are many items in the list and in one item u pressed the play button. The songs starts and the button changes from play to pause. Now if you click the play button of some other list, the new song gets started and the button also changes from play to pause. but the previous button also remains in the pause state, which should return in the previous state. i,e play..

Understood now my friend?
 
Back
Top Bottom