列表视图开始自动执行



我想开发一个我将使用listview的应用程序。每一行都包含一些信息以及音频媒体播放器。媒体播放器也会有一个按钮。当我按下按钮列表视图时,将从索引 0 开始运行并开始播放音乐。它一直运行到我按下暂停按钮。所以这意味着从索引 0 开始到 listview 的最后一个索引。我该怎么做?可能吗。谢谢。

使用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] );
}

最新更新