我Index.class的活动,当用户选择配置文件,它会调用片段档案DialogFragment后刷新片段驳回
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();
}
现在档案片段,当用户点击一个按钮,它会调用DevRegistration活动
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类中,点击注册按钮后,它会显示一个对话框片段类。 我想要做的是当我点击对话框片段中的按钮时,如何刷新配置文件片段?
对话片段类:
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()它崩溃。
使用自定义的监听器接口 –
你可以分享你的对话片段类,好吗? – Cochi