答案 0 :(得分:0)
您可以使用点击或滑动事件
获取第二个片段的实例
SecondFragment fragment = new SecondFragment();
fragmentManager.beginTransaction().replace(R.id.first_container, fragment).commit();
答案 1 :(得分:0)
你可以通过添加Activity然后首先调用前一个片段中的活动,然后在活动中调用所需的片段,最后在活动上添加回按钮来实现。
public class DetailActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
/* ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setCustomView(R.layout.header);
actionBar.setDisplayHomeAsUpEnabled(true); */
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setNavigationIcon(R.drawable.back);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Smart Take Away");
// getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (toolbar != null) {
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
}
// Bundle extras = getIntent().getExtras();
if (savedInstanceState == null) {
try {
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
DetailedListFragment fragment = new DetailedListFragment();
// fragment.setArguments(extras);
fragmentTransaction.replace(R.id.detailfragment, fragment);
fragmentTransaction.commit();
} catch (Exception e) {
e.printStackTrace();
}
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
}