TextView始终在列表的最后一个textview中设置文本

时间:2017-05-10 16:02:29

标签: android

我正在尝试设置正在适配器中的ListView中播放的当前曲目的TextView。会发生什么是TextView的位置错误,它总是将文本设置在列表中可用的最后一个TextView中。这就是我做到的。

public void startPlayProgressUpdater(final SeekBar seek, final Button start) {
    seek.setProgress(mediaPlayer.getCurrentPosition());


    if (mediaPlayer.isPlaying()) {
        Runnable notification = new Runnable() {
            public void run() {
                startPlayProgressUpdater(seek,start);

                 currentTime.setText(getTimeString(mediaPlayer.getDuration() - mediaPlayer.getCurrentPosition()));


            }
        };
        handler.postDelayed(notification, 1000);
    } else {
        mediaPlayer.pause();
        seek.setProgress(0);
    }
}

1 个答案:

答案 0 :(得分:0)

这是我的代码

private Runnable updateSongTime = new Runnable() {
        public void run() {
            startTime = mediaPlayer.getCurrentPosition();
            playTime.setText(String.format("%02d:%02d/%02d:%02d",
                            TimeUnit.MILLISECONDS.toMinutes((long) startTime),
                            TimeUnit.MILLISECONDS.toSeconds((long) startTime) -
                                    TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.
                                            toMinutes((long) startTime)),
                            TimeUnit.MILLISECONDS.toMinutes((long) finalTime),
                            TimeUnit.MILLISECONDS.toSeconds((long) finalTime) -
                                    TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.
                                            toMinutes((long) finalTime)))
            );
            seekBar.setProgress((int)startTime);
            if(mediaPlayer.isPlaying())
                myHandler.postDelayed(this, 100);
        }
    };

和我的播放按钮

 play.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mediaPlayer.isPlaying()){
                    play.setBackgroundResource(R.drawable.ic_action_play);
                    mediaPlayer.pause();
                }
                else {
                    mediaPlayer.start();
                    finalTime = mediaPlayer.getDuration();
                    startTime = mediaPlayer.getCurrentPosition();

                    seekBar.setMax((int) finalTime);

                    seekBar.setProgress((int) startTime);
                    myHandler.postDelayed(updateSongTime, 100);
                    play.setBackgroundResource(R.drawable.ic_action_pause);
                }
            }
        });

看看它对你有帮助。

ANKIT