androidandroid-fragmentsrecreate

Cannot resolve method 'recreate()' in fragment


recreate() cant be resolved in fragment activity.

mBuilder.setSingleChoiceItems(listItems, -1, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int i) {


                if( i==0 )
                {setLocale("per");
                    recreate();}


                if( i==1 )
                {setLocale("en");
                    recreate();}

            dialog.dismiss();
        }
    });

I use this method in fragment activity as below:

public class SettingsFragment extends Fragment implements FragmentArguments {

Solution

  • There is no recreate method in a Fragment. Its a method inherited from an Activity. If you want the recreate the Activity from the fragment, you can call

    getActivity().recreate();
    

    If you want to reload just the Fragment, you can detach the fragment and then attach it again like this.

    getSupportFragmentManager()
        .beginTransaction()
        .detach(YourFragment.this)
        .attach(YourFragment.this)
        .commit();