Hey
- User
Hey
- Assistant
Hello! How can I assist you today?
- User
Im doing an android app. Can you help me a bit?
- Assistant
Of course! I'd be happy to help with your Android app development. What do you need assistance with?
- User
I have a Main Activity which has a bottom navigation bar, and each time new menu item is selected by user im using FragmentTransaction to change fragments. But one of my fragment fetches some user data from the web and changes views with this data. So each time im clicking on this menu item it fetches data. How do i cache it and only update when user swipes down?
- Assistant
- User
Can you show the examples not in kotlin but java?
- Assistant
- User
i think this approach is more for real-time solutions, but my app is not something like that
- Assistant
- User
just check the code that is used every time fragment is displayed, make it so it updates only when created first time
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_profile, container, false); view.findViewById(R.id.button).setOnClickListener(v -> { Client.getStorage().edit().clear().apply(); startActivity(new Intent(view.getContext(), LoginActivity.class)); }); SwipeRefreshLayout swipe = view.findViewById(R.id.swiperefresh); swipe.setVisibility(View.INVISIBLE); swipe.setOnRefreshListener(() -> fetchUpdateUi(view, () -> swipe.setRefreshing(false))); TextView profileText = view.findViewById(R.id.profileTextView); if (profileText.getText().toString().isEmpty()) { ConstraintLayout loadingLayout = view.findViewById(R.id.loadingLayout); loadingLayout.setVisibility(View.VISIBLE); fetchUpdateUi(view, () -> { loadingLayout.setVisibility(View.GONE); swipe.setVisibility(View.VISIBLE); }); } return view; } - Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.