可以在此处找到更多回调/与其他片段的通信:
Communicating with Other Fragments
public class FragmentA extends Fragment { public voID updateMyself(String updateValue){ Log.v("update","weeee Fragment B updated me with" + updateValue); }}public class FragmentB extends Fragment { public Interface FragmentBCallBackInterface { public voID update(String updateValue); } private FragmentBCallBackInterface mCallback; @OverrIDe public voID onAttach(Activity activity) { super.onAttach(activity); try { mCallback = (FragmentBCallBackInterface) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement FragmentBCallBackInterface"); } //As an example we do an update here - normally you wouln't call the method until your user performs an onclick or something letsUpateTheOtherFragment(); } private voID letsUpateTheOtherFragment(){ mCallback.update("This is an update!); }}public class MyActivity extends Activity implements FragmentInterfaceB { @OverrIDe public voID update(String updateValue){ FragmentA fragmentA = (FragmentA) getSupportFragmentManager().findFragmentByID(R.ID.article_fragment); if (fragmentA != null) { fragmentA.updateMyself(updateValue); } else { //replace the fragment... bla bla check example for this code } }}总结
以上是内存溢出为你收集整理的Android:按下后退按钮时刷新上一个片段数据全部内容,希望文章能够帮你解决Android:按下后退按钮时刷新上一个片段数据所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)