【问题标题】:How do refresh RecyclerView of one fragment by button click in another fragment如何通过在另一个片段中单击按钮来刷新一个片段的 RecyclerView
【发布时间】:2018-12-14 09:56:29
【问题描述】:

我在一个活动中有两个片段。 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);

【问题讨论】:

标签: android


【解决方案1】:
【解决方案2】:

我希望您了解广播接收器,如果没有,请阅读此处Android Broadcast Receiversdetail practical implementation 并使用本地广播接收器来执行此操作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 2018-10-11
    • 2020-08-12
    • 1970-01-01
    • 2022-01-25
    相关资源
    最近更新 更多