我想做一个RESET按钮。我已经成功地完成了Spinner和Seekbar的工作,但未能完成RecyclerView的工作,这是我的过滤结果。没有错误,但是正如您在我的输出界面中看到的那样,只有recyclerView并不为空...
我的编码:-
resetButton.setOnClickListener(new View.OnClickListener() {
final MediaPlayer mediaPlayer = MediaPlayer.create(FilterTuitionCentre.this, R.raw.soundeffect1);
@Override
public void onClick(View v) {
mediaPlayer.start();
spLocation.setSelection(0);
seekbarPrice.setProgress(0);
spAcademicLevel.setSelection(0);
spSubject.setSelection(0);
recyclerView.invalidate();
}
});
我的界面输出:-
我的适配器编码:-
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setAdapter(mAdapter);
答案 0 :(得分:1)
我假设您对您的recyclerView进行了以下初始化:
YourAdapter adapter = new YourAdapter(items);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
要清除物品(空)RecyclerView,您需要:
items.clear();
adapter.notifyDataSetChanged();