Update of fragment



  • There's a function. refresh() in a fragment that updates its contents. How can the function be static so that it can be called from another class?

      public class LoftFragment extends Fragment {
            public static String LOG_TAG = "my_log";
            static TextView temp_indor;
            static TextView humidity_indor;
    
        @Nullable
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.loft_layout, container, false);
            temp_indor = (TextView) view.findViewById(R.id.temp_indor);
            temp_indor.setText(ParseData.value_temp_indor);
            humidity_indor = (TextView) view.findViewById(R.id.humidity_indor);
            humidity_indor.setText(ParseData.value_humidity_indor);
            return view;
        }
    
        public static void refresh() {
            FragmentTransaction ft = getFragmentManager().beginTransaction();
            ft.detach(this).attach(this).commit();
        }
    }
    



  • I know three options:

    1. Statutory function and use it LoftFragment.refresh() (Big option, I wouldn't recommend that)

    2. Through the interface.

    3. And the best option is to use a copy of the object: Somewhere upstairs, Fragment loftFragment = new LoftFragment(); Then loftFragment.refresh()

    The third way is to refrigerate from activism, or you have to do it through the interface.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2