我從數據庫中提取數據並將其顯示爲RecyclerView
。但我必須更新RecyclerView
每x milliseconds/seconds
。我必須更新我的RecyclerView適配器每x秒
這是我的代碼。請幫忙。
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.fragment_download, container, false);
rvLatestTrack = (RecyclerView) view.findViewById(R.id.recyclerview);
linearLayoutEmpty = (LinearLayout) view.findViewById(R.id.linearLayoutEmpty);
arrayList = new ArrayList<>();
rvLatestTrack.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
getData();
return view;
}
public void getData() {
Database database = new Database(getContext());
SQLiteDatabase sqLiteDatabase = database.getWritableDatabase();
String SELECT_DATA_QUERY = "SELECT * FROM " + DB_Const.TABLE_NAME_SONGS;
Cursor cursor = sqLiteDatabase.rawQuery(SELECT_DATA_QUERY, null);
if (cursor.getCount() != 0) {
if (cursor.moveToFirst()) {
DownloadsModel downloadsModel;
do {
String fileName = cursor.getString(cursor.getColumnIndex(DB_Const.SONG_TITLE));
String Download_percentage = cursor.getString(cursor.getColumnIndex(DB_Const.Completed_percentage));
String SongURL = cursor.getString(cursor.getColumnIndex(DB_Const.URL));
downloadsModel = new DownloadsModel(fileName, Download_percentage, SongURL);
arrayList.add(downloadsModel);
} while (cursor.moveToNext());
rvLatestTrack.setAdapter(new DownloadsAdaptor(getContext(), arrayList));
}
cursor.close();
} else {
linearLayoutEmpty.setVisibility(View.VISIBLE);
}
}
這只是做一次 – Thinsky
沒有得到你嗎? –
未解決問題 –