无法解析片段中的方法'recreate()'

时间:2019-04-20 11:22:53

标签: android android-fragments recreate

recreate()无法在片段活动中解析。

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();
        }
    });

我在片段活动中使用此方法,如下所示:

public class SettingsFragment extends Fragment implements FragmentArguments {

1 个答案:

答案 0 :(得分:1)

片段中没有重新创建方法。它是从Activity继承的方法。如果要从片段中重新创建活动,可以调用

getActivity().recreate();

如果只想重新加载片段,则可以分离该片段,然后像这样再次附加它。

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