如何通过按钮单击另一个片段来刷新一个片段的RecyclerView

时间:2018-12-14 09:56:29

标签: android

我在一个活动中有两个片段。 RecordFragment记录音频,RecordingsFragment显示所有记录音频。 我的问题是单击RecordFragment中的停止按钮后如何刷新RecordingsFragment的RecyclerView。

RecordFragment

RecordingsFragment

这是适配器的代码。 Utils.getListOfNames()从存储中检索文件列表。

mRecyclerView = rootView.findViewById(R.id.recyclerView);
mAdapter = new RecordingsListAdapter(Utils.getListOfNames(), getContext());
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

这是stopButton的onClick

Toast.makeText(getContext(), "Stop clicked ", Toast.LENGTH_SHORT).show();
mediaRecorder.stop();
startButton.setVisibility(View.VISIBLE);
stopButton.setVisibility(View.GONE);

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

我希望您了解广播接收器,如果不是这样的话,请在这里Android Broadcast Receiversdetail practical implementation进行阅读,并使用本地广播接收器来做到这一点。