Android Listview具有seekbar的多个项目,seekbar进度不适用于当前点击位置[问题]

Android Listview具有seekbar的多个项目,seekbar进度不适用于当前点击位置[问题],android,listview,android-mediaplayer,onitemclicklistener,android-seekbar,Android,Listview,Android Mediaplayer,Onitemclicklistener,Android Seekbar,我现在在listview中使用mediaplayer,它工作得很好,每一个itemonclick,不同的音频将在当前位置播放。但我现在面临的问题是: 我创建的每个项目都有一个Seekbar来显示mediaplay的进度。seekbar在第一个onItemclick中运行良好,是的,只是第一个项目,一旦用户单击第二个项目,上一个(第一个单击的项目seekbar)和当前单击的seekbar将一起运行,一旦用户单击第三个项目,前两个(第一个和第二个单击的项目seekbar也将随之运行)当前单击的see

我现在在listview中使用mediaplayer,它工作得很好,每一个itemonclick,不同的音频将在当前位置播放。但我现在面临的问题是: 我创建的每个项目都有一个Seekbar来显示mediaplay的进度。seekbar在第一个onItemclick中运行良好,是的,只是第一个项目,一旦用户单击第二个项目,上一个(第一个单击的项目seekbar)和当前单击的seekbar将一起运行,一旦用户单击第三个项目,前两个(第一个和第二个单击的项目seekbar也将随之运行)当前单击的seekbar将一起运行。 对不起,我的英语不好,希望你们都能帮助我。请和谢谢:) 我的代码如下: MessageAdapter.java->

 public void playSong(final int position,final TextView msgText, final SeekBar finaltime, final TextView voiceduration,
                     final SeekBar showprogress, final ImageView playbutton){

    /*  File filepath = new File(Environment.isExternalStorageEmulated() +  "/"+ AUDIO_RECORDER_FOLDER + "/1444021246887.amr");*/
    final Message infoposition = mMessage.get(position);
    final int infodeid = infoposition.getId();
    Log.d("adaptersong1","adaptersongtry" + infodeid);
    db = new DBHelper(getContext());
    db.getVoicePath(infodeid);
    String databasevoicepath = db.getVoicePath(infodeid);
    Log.d("adaptersong2", "adaptersongtry" + databasevoicepath);

    File filePath = new File(databasevoicepath);
    audio.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            audio.reset();

            changeicon(playbutton);
            setMsgText(msgText);


        }
    });
    Log.d("adaptersong3", "adaptersongtry" + filePath);


    try {
        audio.setDataSource(String.valueOf(filePath));
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        audio.prepare();
    } catch (IOException e) {
        e.printStackTrace();
    }

    audio.start();
    finalTime = audio.getDuration();
    Log.d("getduration","simentimecheck" + finalTime);
    startTime = audio.getCurrentPosition();
    Log.d("getPosition", "simentimecheck" + startTime);
    if (oneTimeOnly == 0) {
        setFinalTime(finaltime);
       /* voiceseekbar.setMax((int) finalTime);*/
        oneTimeOnly = 1;
    }


    seekbarprogress(showprogress);


    setDuration(voiceduration);

}

private void changeicon(ImageView playbutton){
    playbutton.setImageResource(R.drawable.play);
}

private void seekbarprogress(SeekBar showprogress) {


    showprogress.setProgress((int)startTime);
    myHandler.postDelayed(createRunnable(showprogress), 100);
}


private Runnable createRunnable(final SeekBar createSeekbarAgain)

{
     Runnable UpdateSongTime = new Runnable() {
        public void run() {
            startTime = audio.getCurrentPosition();
            seekbaragain(createSeekbarAgain);
            myHandler.postDelayed(this, 100);
        }
    };
    return UpdateSongTime;
}

private void seekbaragain(SeekBar createSeekbarAgain){
    createSeekbarAgain.setProgress((int) startTime);
}

private void setDuration(TextView voiceduration){
    if( TimeUnit.MILLISECONDS.toSeconds((long) finalTime) -
            TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) finalTime)) < 10){
        voiceduration.setText(String.format("00:0%d ",
                        TimeUnit.MILLISECONDS.toSeconds((long) finalTime) -
                                TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) finalTime)))
        );
    }else{
        voiceduration.setText(String.format("00:%d ",
                TimeUnit.MILLISECONDS.toSeconds((long) finalTime) -
                        TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) finalTime))));
    }


}
private void setFinalTime(SeekBar finaltime){
    finaltime.setMax((int) finalTime);
}
public void playSong(最终int位置、最终TextView msgText、最终SeekBar最终时间、最终TextView voiceduration、,
最终搜索栏显示进度、最终图像视图播放按钮){
/*File filepath=新文件(Environment.isExternalStorageEmulated()+“/”+音频记录器文件夹+“/144402146887.amr”)*/
最终消息infoposition=mMessage.get(位置);
final int infodeid=infoposition.getId();
Log.d(“adaptersong1”、“adaptersongtry”+infodeid);
db=newdbhelper(getContext());
db.getVoicePath(infodeid);
字符串databasevoicepath=db.getVoicePath(infodeid);
Log.d(“adaptersong2”、“adaptersongtry”+数据库语音路径);
文件路径=新文件(databasevoicepath);
setOnCompletionListener(新的MediaPlayer.OnCompletionListener(){
@凌驾
完成时的公共作废(MediaPlayer mp){
audio.reset();
更改图标(播放按钮);
设置msgText(msgText);
}
});
Log.d(“adaptersong3”、“adaptersongtry”+文件路径);
试一试{
setDataSource(String.valueOf(filePath));
}捕获(IOE异常){
e、 printStackTrace();
}
试一试{
audio.prepare();
}捕获(IOE异常){
e、 printStackTrace();
}
audio.start();
finalTime=audio.getDuration();
Log.d(“getduration”、“simentimecheck”+finalTime);
startTime=audio.getCurrentPosition();
Log.d(“getPosition”、“simentimecheck”+startTime);
if(oneTimeOnly==0){
设置最终时间(最终时间);
/*voiceseekbar.setMax((int)finalTime)*/
一次性=1;
}
seekbarprogress(showprogress);
设置持续时间(voiceduration);
}
私有无效更改图标(ImageView播放按钮){
playbutton.setImageResource(R.drawable.play);
}
私有void seekbarprogress(SeekBar showprogress){
showprogress.setProgress((int)startTime);
postDelayed(createRunnable(showprogress),100);
}
私有可运行createRunnable(最终SeekBar createSeekbarAgain)
{
Runnable UpdateSongTime=new Runnable(){
公开募捐{
startTime=audio.getCurrentPosition();
seekbaragain(createSeekbarAgain);
myHandler.postDelayed(这个,100);
}
};
返回UpdateSongTime;
}
私有void seekbaragain(SeekBar createSeekbarAgain){
createSeekbarAgain.setProgress((int)startTime);
}
私有void setDuration(TextView voiceduration){
if(时间单位毫秒到秒((长)最终时间)-
TimeUnit.MINUTES.toSeconds(TimeUnit.millizes.toMinutes((长)finalTime))<10){
voiceduration.setText(String.format(“00:0%d”),
时间单位。毫秒。到秒((长)最终时间)-
TimeUnit.MINUTES.toSeconds(TimeUnit.millides.toMinutes((long)finalTime)))
);
}否则{
voiceduration.setText(String.format(“00:%d”),
时间单位。毫秒。到秒((长)最终时间)-
TimeUnit.MINUTES.toSeconds(TimeUnit.ms.toMinutes((long)finalTime));
}
}
私有无效设置最终时间(参见KBAR最终时间){
setMax((int)finaltime);
}

请帮助:)如果您需要查看更多代码以获取更多信息,请发表评论,我愿意这样做。

如何将搜索栏传递到
playSong
方法,它看起来像是一个转换视图issue@Neil先生,我通过调用seekbarprogress(showprogress)方法传入seekbar;这是Playsong()方法的最后一步了你从来没有停止过上一个搜索栏吗?@Neil是的,先生,我甚至不知道如何停止搜索栏我以前尝试过myHandler.removecallbacks,但它不起作用,或者我可能在错误的位置插入代码请帮助,对不起,我对Android太陌生了。如何将搜索栏传递给
playSong
方法,它看起来像一个转换视图issue@Neil先生,我通过调用seekbarprogress(showprogress)方法传入seekbar;这是Playsong()方法的最后一步了你从来没有停止过上一个搜索栏吗?@Neil是的,先生,我甚至不知道如何停止搜索栏我以前尝试过myHandler.removecallbacks,但它不起作用,或者我可能在错误的位置插入代码请帮助,对不起,我对android太陌生了