同一個activity中不同fragment的跳轉
阿新 • • 發佈:2019-02-07
activity
public class BorrowFlow extends BaseActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_borrowflow);
if (savedInstanceState == null) {
getSupportFragmentManager()
.beginTransaction()
.add(R.id.container, new BorrowFirst())
.commit();
}
}
fragmentOne核心跳轉方法
private void submit() {
// validate
String borrowString = borrow.getText().toString().trim();
if (TextUtils.isEmpty(borrowString)) {
Toast.makeText(getContext(), "請填寫您的借款額度", Toast.LENGTH _SHORT).show();
return;
}
String dayString = day.getText().toString().trim();
if (TextUtils.isEmpty(dayString)) {
Toast.makeText(getContext(), "7/14", Toast.LENGTH_SHORT).show();
return;
}
// TODO validate success, do something
getFragmentManager()
.beginTransaction ()
.addToBackStack(null) //將當前fragment加入到返回棧中
.replace(R.id.container, new BorrowSecond()).commit();
}