【发布时间】:2022-07-02 08:51:33
【问题描述】:
我使用 ViewModel 和 LiveData 调用 Retrofit API。
public LiveData<List<History>> getHistory(Context context, String queryType, long from, long to) {
return HistoryDataRepository.getInstance(context).getLocationHistory(queryType, from, to);
}
我在我的 Fragment 中使用这个函数,如下所示:
viewModel.getHistory(requireContext(), ConstantsHelper.QUERY_TYPE, fromDate, toDate).observe(this, data -> {
..
..
..
}
我想创建一个 HistoryHelper 类并将这个函数移动到我的助手类中,以使我的代码更有条理。
如何在我的自定义助手类中使用 ViewModel 函数?
【问题讨论】: