兩個fragment 同時跳轉另一個fargment ,返回對應的fragment 的解決方法

安卓app主頁面爲 FragmentActivity,其他頁面爲fragmnet頁面。app



主頁面  底部導航欄 三個按鈕。 點擊三個按鈕分別跳轉不一樣的  frgment .若是  點擊這個三個按鈕時,其中兩個或者三個再者一個 ,  須要 判斷  用戶是否登陸,(固然跳轉的登陸頁面也是  frgment頁面)。那麼 跳轉到登陸頁面  ,登陸成功後 如何返回spa

主頁面  按鈕 對應的 fragment  呢? 這裏爲你們講解一下  解決方案!固然這僅僅是針對於  本人項目的解決 方法。不過可能對你  有用哦。get


首頁先  貼出  主頁面   FragmentActivity   裏面  判斷的代碼:it


private void eventUser() {io

// TODO Auto-generated method stubevent

buttonChange(2);class


if (MyApplication.instance.getUserData() != null) {登錄

changFragment(new UserFragment(), "UserFragment");fragment

} else {方法

UserLoginFragment mUserLoginFragment = new UserLoginFragment();

FragmentManager fm = getSupportFragmentManager();

FragmentTransaction ft = fm.beginTransaction();

Bundle mBundle = new Bundle();

mBundle.putString("user",UserFragment.class.getSimpleName() );

mUserLoginFragment.setArguments(mBundle);

ft.replace(R.id.llfragment, mUserLoginFragment);

ft.addToBackStack("UserTag");


ft.commit();


}


}


private void eventLoan() {

// TODO Auto-generated method stub

buttonChange(1);

if (MyApplication.instance.getUserData() != null) {

changFragment(new LoanFragment(), "LoanFragment");

} else {

UserLoginFragment mUserLoginFragment = new UserLoginFragment();

FragmentManager fm = getSupportFragmentManager();

FragmentTransaction ft = fm.beginTransaction();

Bundle mBundle = new Bundle();

mBundle.putString("loan", LoanFragment.class.getSimpleName());

mUserLoginFragment.setArguments(mBundle);

ft.replace(R.id.llfragment, mUserLoginFragment);

ft.addToBackStack("LoanTag");

ft.commit();


}


}

跳轉到  登陸頁面的代碼(這裏代碼看你怎麼處理就放在那裏):


                                               FragmentManager fm;

FragmentTransaction ft;


String mUser = getArguments().getString("user");


String mLoan = getArguments().getString("loan");


if (UserFragment.class.getSimpleName().equals(mUser)) {

UserFragment mUserFragment = new UserFragment();

fm = getFragmentManager();

ft = fm.beginTransaction();


ft.replace(R.id.llfragment, mUserFragment);

ft.addToBackStack("UserTag");

ft.commit();


} else if (LoanFragment.class.getSimpleName().equals(

mLoan)) {

LoanFragment mLoanFragment = new LoanFragment();

fm = getFragmentManager();

ft = fm.beginTransaction();


ft.replace(R.id.llfragment, mLoanFragment);

ft.addToBackStack("LoanTag");

ft.commit();

}

但願幫助到你們。

相關文章
相關標籤/搜索