fragment相互切换
底部的四个按钮,其中一个按钮对应的fragment有editview,修改其中内容,切换另一个fragment再切换回来的时候editview的内容清空了,要怎么解决?
底部的四个按钮,其中一个按钮对应的fragment有editview,修改其中内容,切换另一个fragment再切换回来的时候editview的内容清空了,要怎么解决?
2018-02-09
@Bind(R.id.mRb_server)
RadioButton mRbServer;
@Bind(R.id.mRb_wx)
RadioButton mRbWx;
@Bind(R.id.mRb_girl)
RadioButton mRbGirl;
@Bind(R.id.mRb_person)
RadioButton mRbPerson;
@Bind(R.id.rl_container)
FrameLayout rlContainer;
@Bind(R.id.rg_buttom)
RadioGroup rgButtom;
private BaseFragment mFragmentServer,mFragmentWx,mFragmentGirl,mFragmentPerson,currentFragment;
@Override
public int getLayoutId() {
logUtils.logD("getLayoutId","getLayoutId");
return R.layout.activity_main;
}
@Override
public void initView() {
logUtils.logD("initView","initView");
setListener();
}
private void setListener() {
rgButtom.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
handleOnClick(checkedId);
}
});
}
private void handleOnClick(int checkedId) {
switch (checkedId){
case R.id.mRb_server :
switchFragment(mFragmentServer);
break;
case R.id.mRb_wx :
switchFragment(mFragmentWx);
break;
case R.id.mRb_girl :
switchFragment(mFragmentGirl);
break;
case R.id.mRb_person :
switchFragment(mFragmentPerson);
break;
default:
break;
}
}
private void switchFragment(BaseFragment fragment){
FragmentTransaction tran = getSupportFragmentManager().beginTransaction();
tran.show(fragment);
tran.hide(currentFragment);
tran.commit();
currentFragment=fragment;
}
@Override
public void initData() {
mFragmentServer=new Fragment_Server_Manager();
mFragmentWx=new Fragment_Wx_Selected();
mFragmentGirl=new Fragment_Girl();
mFragmentPerson=new Fragment_Personnal();
FragmentTransaction tran = getSupportFragmentManager().beginTransaction();
tran.add(R.id.rl_container,mFragmentServer);
tran.add(R.id.rl_container,mFragmentWx).hide(mFragmentWx);
tran.add(R.id.rl_container,mFragmentGirl).hide(mFragmentGirl);
tran.add(R.id.rl_container,mFragmentPerson).hide(mFragmentPerson);
currentFragment=mFragmentServer;
tran.commit();
}
举报