我想开发一个应用程序,我将使用listview。每一行都包含一些信息以及音频媒体播放器。媒体播放器也会有一个按钮。当我按下按钮列表视图将从索引0开始操作并开始播放音乐。它会一直运行,直到我按下暂停按钮。这意味着从索引0开始到列表视图的最后一个索引。我怎样才能做到这一点?可能吗。谢谢。
答案 0 :(得分:0)
使用recyclerView加上AsyncTask和ScheduledThreadPoolExecutor非常简单:
@Override
protected Void doInBackground( Void... params ) {
schedule();
return null;
}
void schedule() {
mExecutor.schedule( () -> {
// do your calculation here like the scroll speed and conditions
// Example: if the list item has height of 100px and the audio also has length 100 seconds, that means you have to scroll for 1px in every second
int scrollPx = calculate();
publishProgress(scrollPx);
if ( !isCancelled() ) {
schedule();
}
}, mScrollDelay, TimeUnit.MILLISECONDS );
}
@Override
protected void onProgressUpdate( Integer... values ) {
recyclerView.scrollBy( 0, values[0] );
}