导航体系结构组件,片段包含从头开始显示的列表,而从另一个片段返回

时间:2019-07-02 18:34:24

标签: java android-studio android-fragments android-architecture-components android-architecture-navigation

方案::假设底部导航栏包含 Home 片段,该片段可以打开另一个片段,例如产品详情。用户可以从“产品详情”片段中打开产品详细信息片段,以查看任何商品的详细信息。

问题::假设用户滚动了“产品详情”片段中的列表,并到达第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.
                }
}

0 个答案:

没有答案
相关问题