daimajia / daimajia/AndroidSwipeLayout
SwipeLayout as ListView item: SeekBar updating multiple time with recycled child views
- Dominant language
- Java
- Stars
- 12.3k
- Forks
- 2.6k
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
I am using this project in my new app which shows a list of tracks with a play button and a SeekBar progress. I am able to get the tracks playing but I got an issue with updating the SeekBar.
- I use a Runnable and a Handler to update the SeekBar.
- When I hit play, the SeekBar of that child view, moving correctly, but the child at its recycled position got updated too. For example, I have a list of 10 items, with 5 visible items only. When 1st track's SeekBar got updating, the 6th track was also updated. The same thing happening with 11th or 16th... positions if I have bigger list.
Any suggestion to how I could get it updated properly?
**child_item.xml**
``` xml
```
**ListViewAdapter.java**
``` java
@Override
public void fillValues(int position, View convertView) {
ImageButton imageButton = (ImageButton) convertView.findViewById(R.id.buttonPlayPause);
TextView t = (TextView)convertView.findViewById(R.id.songName);
SeekBar seekbar = (SeekBar) convertView.findViewById(R.id.progressBar);
String url = adapterData[position];
MediaPlayer mp = mpUtils.getMediaPlayer(url);
imageButton.setTag(R.id.TAG_MEDIAPLAYER, mp);
imageButton.setBackgroundResource(R.drawable.ic_media_play);
Runnable updateProgress = new UpdateSongTime(mp,seekbar);
imageButton.setOnClickListener(new playButtonClicked(position,updateProgress));
t.setText((position + 1) + ".");
}
private class UpdateSongTime implements Runnable {
MediaPlayer mediaPlayer;
SeekBar seekBar;
double startTime = 0;
public UpdateSongTime(MediaPlayer mp, SeekBar sb){
this.mediaPlayer = mp;
this.seekBar = sb;
}
public void run() {
startTime = mediaPlayer.getCurrentPosition();
seekBar.setProgress((int)startTime);
myHandler.postDelayed(this, 100);
}
};
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.