Tabs fragment fetch data every time I change tab

前端 未结 1 1267
Happy的楠姐
Happy的楠姐 2021-01-23 14:02

activity_profile.xml




        
1条回答
  •  耶瑟儿~
    2021-01-23 14:39

    If you go to 3rd tab then go to the 2nd or 1st tab then 1st will be recreated and call onCreate, that is the default behavior of fragment. But going to just 2nd tab and then back to 1st tab will not recreate the 1st tab. I have made some changes in the InterestTabFragment.java below only in onCreate. See if it helps, if not then notify me, I may try again. Thanks.....

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreateView(inflater, container, savedInstanceState);
        view = inflater.inflate(R.layout.interest_tab_fragment, container, false);
    
        listview = (HorizontalListView) view.findViewById(R.id.LVCategory);
    
            if(((ProfileActivity)getActivity()).interestResult.categories == null){
                Session session = Session.getActiveSession();
                if (session != null && session.isOpened()) {
                    // Get the user's data
                    access_token = session.getAccessToken();
                    makeInterestRequest(session);
            }
            } else {
                CategoryLVAdapter adapter = new CategoryLVAdapter(getActivity(), R.layout.category_item_template,     ((ProfileActivity)getActivity()).interestResult.categories);
    
                listview.setAdapter(adapter);
            }
    
    
        return view;
    }
    

    0 讨论(0)
提交回复
热议问题