我有Index.class作为Activity,当用户选择Profile时,它会调用 fragment Profile
if (id == R.id.nav_profile){
FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction();
transaction.setCustomAnimations(R.anim.enter,R.anim.exit,R.anim.enter,R.anim.exit);
transaction.replace(R.id.flContent, new Profile(), "ProfileFragment");
transaction.addToBackStack(null);
viewPager.getAdapter().notifyDataSetChanged();
transaction.commit();
}
现在在 Profile Fragment 中,当用户单击按钮时,它将调用 DevRegistration Activity
case 1:
btnBeDeveloper.setText("Developer Console");
btnBeDeveloper.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent index = new Intent(getActivity(), DevRegistration.class);
startActivity(index);
}
});
break;
然后在 DevRegistration 类中,点击注册按钮后,会显示一个对话框 fragment 类。
我想要做的是当我单击对话框 fragment 内的按钮时,如何刷新配置文件 fragment ?
对话框 fragment 类:
public class df_SuccessDevRegistration extends DialogFragment {
Button btnDevGoProfile;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
View rootView = inflater.inflate(R.layout.fragment_success_developer_registration, container, false);
btnDevGoProfile = (Button) rootView.findViewById(R.id.btnDevGoProfile);
btnDevGoProfile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
getFragmentManager().popBackStack();
getActivity().finish();
Profile fragment = (Profile)
getSupportFragmentManager().findFragmentByTag("ProfileFragment");
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction()
transaction.detach(fragment);
transaction.attach(fragment);
transaction.commit();
}
});
return rootView;
}
}
顺便说一句,我不知道为什么 getSupportFragmentManager 不起作用。它显示错误无法解析方法...当我使用 getFragmentManager() 时它崩溃了。
最佳答案
您也可以尝试刷新当前 fragment
FragmentTransaction ftran = getActivity().getFragmentManager().beginTransaction();
ftran .detach(this).attach(this).commit();
关于android - DialogFragment 关闭后重新加载 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42851991/