[英]How can I do with android Fragment backstack?
我有四个片段ABCD。当我执行从A到B的跳跃以及从B到C的跳跃以及从C到D的跳跃时,按返回键如何获得D到B的结果?
FragmentD: FragmentD:
Create an interface in FragmentD. 在FragmentD中创建一个接口。
OnBackListener mback;
public interface OnBackListener {
public void onBackClicked();
}
@Override
public void onAttach(Activity activity) {
try {
mback = (OnBackListener ) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnBackListener");
}
super.onAttach(activity);
}
public void methodCall()
{
mback.onBackClicked()
}
then 然后
Parent Activity 家长活动
Implement the OnBackListener interface that we created in FragmentD. 实现我们在FragmentD中创建的OnBackListener接口。
public class MyActivity extends FragmentActivity implements OnBackListener {
// overriding OnBackListener interface method
@Override
public void onBackClicked() {
//calling fragmentb
}
//Backkey event
@Override
public void onBackPressed()
{
super.onBackPressed();
fragmentd.methodCall();
}
}
In the way, you will get result of fragmentD to fragmentB. 这样,您将得到fragmentD的结果到fragmentB。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.