java - 导航架构组件,包含列表的片段从开始显示,而从另一个片段返回
问题描述
场景:假设底部导航栏包含Home片段,可以打开另一个片段,比如Product Listing。从产品列表片段中,用户可以打开产品详细信息片段以查看任何项目的详细信息。
问题:假设用户滚动了产品列表片段中的列表并到达第 100 个项目并点击一个项目以在产品详细信息片段中查看其详细信息。现在,当用户按下返回按钮以返回产品列表片段时,列表将从头开始显示。
有什么办法或解决办法来克服这个问题。我想在回来时向用户展示第 100 个项目。
产品列表片段的重写方法 Onstart()、OnCreateView()、OnViewCreated()、OnResume() 在从产品详细信息片段返回时执行。
View view;
Unbinder unbinder;
@Override
public View onCreateView(@NotNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (view == null) {
view = inflater.inflate(R.layout.product_listing_screen, container, false);
return view;
} else {
return view;
}
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Timber.e("%s onViewCreated Called ", TAG);
unbinder = ButterKnife.bind(this, view);
}
@Override
public void onResume() {
super.onResume();
Timber.e("%s onResume Called ", TAG);
if (adapter == null || adapterList.size() == 0) {
updateProductListingCategory(itemId); // This is the method making a web request. And while coming back from detail fragment, it isn't called again.
}
}
解决方案
推荐阅读
- javascript - 如何在 jQuery/Java 脚本中调用动态 td 值
- python - 是否可以根据每日滚动标准偏差值计算总标准偏差
- javascript - Redux 表单同步字段级别验证无法使用复杂的字段名称?
- spring-boot - 带有布局集的 Vaadin Flow @Route 注释打破了布局样式
- ruby-on-rails - 对象的未定义方法“distance_of_time_in_words”
- python - 需要帮助将矩阵公式转换为 Python 代码
- java - 如何从 es256 pem 文件 java 中编码 jwtToken
- php - 不使用表单标签的 Ajax 表单
- python - selenium 'nonetype' 对象没有属性 'send_keys'
- laravel - 带有负载均衡器的 laravel 项目的状态 419