关于谷歌官方对fragment交互数据的例子理解
来源:互联网 发布:linux公社 ftp 乱码 编辑:程序博客网 时间:2024/06/05 07:46
这个主要说一下fragment与activity之间的数据交互,以及两个fragment之间的交互,其实跟我之前工作中总结的fragment知识差不多,这里就再复习一下,
- public class HeadlinesFragment extends ListFragment {
- OnHeadlineSelectedListener mCallback;
- // Container Activity must implement this interface
- public interface OnHeadlineSelectedListener {
- public void onArticleSelected(int position);
- }
- @Override
- public void onAttach(Activity activity) {
- super.onAttach(activity);
- // This makes sure that the container activity has implemented
- // the callback interface. If not, it throws an exception
- try {
- mCallback = (OnHeadlineSelectedListener) activity;
- } catch (ClassCastException e) {
- throw new ClassCastException(activity.toString()
- + " must implement OnHeadlineSelectedListener");
- }
- }
- ...
- }
- @Override
- public void onListItemClick(ListView l, View v, int position, long id) {
- // Send the event to the host activity
- mCallback.onArticleSelected(position);
- }
- public static class MainActivity extends Activity
- implements HeadlinesFragment.OnHeadlineSelectedListener{
- ...
- public void onArticleSelected(int position) {
- // The user selected the headline of an article from the HeadlinesFragment
- // Do something here to display that article
- }
- }
- public static class MainActivity extends Activity
- implements HeadlinesFragment.OnHeadlineSelectedListener{
- ...
- public void onArticleSelected(int position) {
- // The user selected the headline of an article from the HeadlinesFragment
- // Do something here to display that article
- ArticleFragment articleFrag = (ArticleFragment)
- getSupportFragmentManager().findFragmentById(R.id.article_fragment);
- if (articleFrag != null) {
- // If article frag is available, we're in two-pane layout...
- // Call a method in the ArticleFragment to update its content
- articleFrag.updateArticleView(position);
- } else {
- // Otherwise, we're in the one-pane layout and must swap frags...
- // Create fragment and give it an argument for the selected article
- ArticleFragment newFragment = new ArticleFragment();
- Bundle args = new Bundle();
- args.putInt(ArticleFragment.ARG_POSITION, position);
- newFragment.setArguments(args);
- FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- // Replace whatever is in the fragment_container view with this fragment,
- // and add the transaction to the back stack so the user can navigate back
- transaction.replace(R.id.fragment_container, newFragment);
- transaction.addToBackStack(null);
- // Commit the transaction
- transaction.commit();
- }
- }
- }
0 0
- 关于谷歌官方对fragment交互数据的例子理解
- 关于Fragment之间的交互
- Fragment与Fragment之间的数据交互
- 对DCI(数据、上下文、交互)的理解
- 对Fragment的一点理解
- 对Fragment加载的理解
- 从官方api理解fragment,以及fragment的生命周期
- 关于 Android Fragment的官方说明文档
- 使用Fragment实现简单的数据交互
- activity与fragment之间的数据交互
- Fragment与Activity之间的数据交互
- Fragment的数据交互 一 使用Handler
- Fragment与Activity之间的数据交互
- Fragment信息交互之Fragment获取DialogFragment的返回数据
- Fragment信息交互之Fragment获取DialogFragment的返回数据
- extjs和servlet数据交互的例子
- 个人对Fragment的一些理解
- 对Activity和Fragment生命周期的理解
- SITE域名后提示“危险网站”如何处理
- 嵌入式 Linux上的free命令详解
- 为什么人打哈欠时会流泪 ?
- JSTL读取properties文件时的中文问题
- 使用真机访问pc上的Tomcat服务器
- 关于谷歌官方对fragment交互数据的例子理解
- method="get/post",两种方式的区别
- sed提取被其它字符包围的ip地址
- 《第一行代码Android》学习日记5
- Zookeeper-Zookeeper leader选举
- error: RPC failed; result=22, HTTP code = 413 git push时
- C#引用类型的赋值机制
- C#禁止关闭窗体
- phonegap/cordova菜鸟问题汇总(不定期更新)