1.一个FragmentActivity(FragmentsActivity)
2.一个ListFragment(Fragment1),其中有很多标题
3.点击其中一个标题,跳转到一个Fragment(Fragment2),并在此显示点击的标题
注意到Fragment可以通过setArguments和getArguments来通过Bundle传值,在ListFragment的点击事件中,将得到的标题,存放到一个Bundle中,传递到Fragment中,再去设置Fragment中的标题为点击的文字。
Fragment中
public class Fragment2 extends Fragment { private static Bundle bundle; static Fragment2 newInstance(Bundle b){ Fragment2 f2 = new Fragment2(); bundle = b; return f2; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment2, container,false); TextView title = (TextView)v.findViewById(R.id.title2); title.setText(bundle.getString("title")); return v; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } }
Fragment的布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/title2" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" android:gravity="center" android:text="class test" /> <EditText android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="4" android:background="@android:color/holo_green_light" android:gravity="top" /> </LinearLayout>
设置EditText的光标指向第一行
android:gravity="top"
ListFragment中
@Override public void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); System.out.println(l.getChildAt(position)); HashMap<String, Object> view= (HashMap<String, Object>) l.getItemAtPosition(position); String title = view.get("title").toString(); Bundle b = new Bundle(); b.putString("title", title); Fragment2 f2 = Fragment2.newInstance(b); getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.fragments, f2).commit(); }
效果:点击class 3
相关推荐
This book looks at the impact fragments have on Android UI design and their role in both simplifying many common UI challenges and in providing best practices for incorporating rich UI behaviors....
Android Fragments, 2014, pdf
Robin是Activities和fragments之间传递Bundle数据的日志记录库。 它还提供回调功能,将用户访问页面的屏幕视图发送到分析客户端
[Packt Publishing] 动态 UI 开发教程 Android Fragments 实现 英文版 [Packt Publishing] Creating Dynamic UI with Android Fragments E Book ☆ 图书概要:☆ Leverage the power of Android fragments to ...
Trying to meet these demands using Android's traditional activity-centric UI design model is difficult at best. As developers, we need more control than that afforded by activities. We need a new ...
fragments
代码来自博客实例:http://blog.csdn.net/lmj623565791/article/details/42628537 有问题请博客留言~~
android-tutorial, 在android中,特性动画和 Fragments 教程 Android教程这里项目包含两个部分。 属性动画与 fragment 在Android中的应用。属性动画一个简单而完整的演示,可以在安卓中实现。 获取更多信息在 ...
Creating Dynamic UI with Android Fragments Leverage the power of Android Fragments to develop dynamic user interfaces for your apps
nested fragments nested fragments nested fragments nested fragments
Android: ViewPager and Fragments The FragmentPagerActivity class creates the ViewPager and the associated FragmentPagerAdapter.
Trying to meet these demands using Android's traditional activity-centric UI design model is difficult. As developers, we need more control than that afforded by activities. We need a new approach: ...
Trying to meet these demands using Android's traditional activity-centric UI design model is dif cult at best. As developers, we need more control than that afforded by activities. We need a new ...
fragments游戏框架
基于Android框架的动态UI构建(Creating Dynamic UI with Android Fragments, 2nd Edition)-2016英文原版,0积分——该书是2016年最新的第2版,全书154页。
fragements例子 博文链接:https://dasheng.iteye.com/blog/986809
你可以认为fragment是activity的模块化组件,它拥有自己的生命周期,接受它自己的输入事件,你也可以在运行activity的时候添加或者移除它(有点像“子...如此你的app(应用)就能与运行android1.6老版本的系统设备兼容 。
使用Fragment如何创建高性能UI;使用Fragment如何创建高性能UI
#Training:片段 + MVC 该项目由一个Activity组成,该Activity具有关于一个人的基本信息表。 更新“名称”字段时,屏幕标题会更新为问候语。 该项目结构MainActivity :所有责任都在MainActivity 。...
AndroidAutowire, Android视图activity 和 Fragments的Java注释方法 Android自动装配使用Java注释和反射,这个库将允许你用基于注释的方法替换来自 activity 。Fragments 和视图的一些烦人的样板设置。这里知识库在...