如何实现多个Fragment 切换不刷新数据,保留当前状态? Android 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public void switchContent(Fragment from, Fragment to) { if (mContent != to) { mContent = to; FragmentTransaction transaction = mFragmentMan.beginTransaction().setCustomAnimations( android.R.anim.fade_in, R.anim.slide_out); if (!to.isAdded()) { // 先判断是否被add过 transaction.hide(from).add(R.id.content_frame, to).commit(); // 隐藏当前的fragment,add下一个到Activity中 } else { transaction.hide(from).show(to).commit(); // 隐藏当前的fragment,显示下一个 } } } public void switchContent(Fragment from, Fragment to) { if (mContent != to) { mContent = to; FragmentTransaction transaction = mFragmentMan.beginTransaction().setCustomAnimations( android.R.anim.fade_in, R.anim.slide_out); if (!to.isAdded()) { // 先判断是否被add过 transaction.hide(from).add(R.id.content_frame, to).commit(); // 隐藏当前的fragment,add下一个到Activity中 } else { transaction.hide(from).show(to).commit(); // 隐藏当前的fragment,显示下一个 } } }这个确实是可以的。 时光轴的实现 学习android,给我推荐一两本书,谢谢 yahoo appid 如何获取 Android 清空Activity栈方法 急:读取文件 如何不使用support.v7 求教 !!!震动器Vibrator系统状态的问题 android 服务端如何获取客户端传递来的数据(在线 100分) 项目中从相册 或者拍照传照片 改怎么做啊 android studio 寻找学习代码 接收通知后Activity的跳转问题
if (mContent != to) {
mContent = to;
FragmentTransaction transaction = mFragmentMan.beginTransaction().setCustomAnimations(
android.R.anim.fade_in, R.anim.slide_out);
if (!to.isAdded()) { // 先判断是否被add过
transaction.hide(from).add(R.id.content_frame, to).commit(); // 隐藏当前的fragment,add下一个到Activity中
} else {
transaction.hide(from).show(to).commit(); // 隐藏当前的fragment,显示下一个
}
}
}
public void switchContent(Fragment from, Fragment to) {
if (mContent != to) {
mContent = to;
FragmentTransaction transaction = mFragmentMan.beginTransaction().setCustomAnimations(
android.R.anim.fade_in, R.anim.slide_out);
if (!to.isAdded()) { // 先判断是否被add过
transaction.hide(from).add(R.id.content_frame, to).commit(); // 隐藏当前的fragment,add下一个到Activity中
} else {
transaction.hide(from).show(to).commit(); // 隐藏当前的fragment,显示下一个
}
}
}
这个确实是可以的。