performance - 在 fragment android上,按下按钮按钮?

  显示原文与译文双语对照的内容

my Fragments/[B] [B] 用户按下 [A] 按钮suppose或者 [B-sub] 应该将应用程序重定向到 [A] 或者,这样我就有了 4个

我希望你知道我的问题

虽然我已经在主 fragment Activity 中尝试过了,但我知道它只是退出应用程序


private boolean _doubleBackToExitPressedOnce = false;

@Override
public void onBackPressed() {

System.out.println("onBackPressed--");
if (_doubleBackToExitPressedOnce) {
 super.onBackPressed();
 return;
}
this._doubleBackToExitPressedOnce = true;
Toast.makeText(this,"Press again to quit", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
 @Override
 public void run() {

 _doubleBackToExitPressedOnce = false;
 }
}, 2000);
}

时间: 作者:

执行类似的操作,重写 onBackpessed ( )


@Override
 public void onBackPressed()
 {
 if (page == SUB_FRG) 
 super.onBackPressed();//Normal Back
 else 
//Finish activity holding fragment
 }

当你将 fragment 替换为subfragment时,使用如下的addToBackStack(null)


FragmentManager myProfilefragmentManager = getSupportFragmentManager();
 FragmentTransaction myProfilefragmentTransaction = myProfilefragmentManager.beginTransaction();
 myProfilefragmentTransaction.replace(R.id.article_fragment, myProfileFragment).addToBackStack(null).commit();

作者:
...