【FragmentActivity】的简单实例
来源:互联网 发布:软件外包项目网 编辑:程序博客网 时间:2024/05/22 13:17
一、FragmentActivity类
public class DemoFragmentActivity_2 extends FragmentActivity{private ViewPager pager;@Overrideprotected void onCreate(Bundle arg0) {super.onCreate(arg0);setContentView(R.layout.demo_activity_fragment_2);pager = (ViewPager) findViewById(R.id.pager_fragment);pager.setAdapter(new FragmentActivityAdatper(getSupportFragmentManager()));}}
<?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/tv_postion" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="tv_postion"/> <ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="wrap_content"></ListView></LinearLayout>
二、FragmentPaperAdapter类
public class FragmentActivityAdatper extends FragmentPagerAdapter{public FragmentActivityAdatper(FragmentManager fm) {super(fm);}@Overridepublic Fragment getItem(int position) {return MyListFragment.newInstance(position);}@Overridepublic int getCount() {return 4;}}
三、ListFragment类
public class MyListFragment extends ListFragment{private int positon;public static Fragment newInstance(int pos){Fragment instance = new MyListFragment();Bundle args = new Bundle();args.putInt("postion", pos);instance.setArguments(args);return instance;}@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);positon = getArguments()==null?0:getArguments().getInt("postion", 0);}@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {LayoutInflater li = LayoutInflater.from(getActivity());View v = li.inflate(R.layout.demo_activity_listfragment, null);TextView tv = (TextView) v.findViewById(R.id.tv_postion);tv.setText(""+positon);return v;}@Overridepublic void onActivityCreated(Bundle savedInstanceState) {super.onActivityCreated(savedInstanceState);setListAdapter(new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,new String[]{"a","b","c"} ));}}
<?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/tv_postion" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="tv_postion"/> <ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="wrap_content"></ListView></LinearLayout>
- 【FragmentActivity】的简单实例
- FragmentActivity类的使用
- FragmentActivity
- FragmentActivity
- fragmentActivity
- Fragment和FragmentActivity的使用方法 .
- Fragment和FragmentActivity的使用方法
- Fragment和FragmentActivity的使用方法 .
- Fragment 和 FragmentActivity的使用
- Fragment和FragmentActivity的使用方法
- Fragment和FragmentActivity的使用方法
- Fragment 和 FragmentActivity的使用
- Fragment与FragmentActivity的关系
- Fragment 和 FragmentActivity的使用
- Fragment和FragmentActivity的使用方法 .
- Fragment 和 FragmentActivity的使用
- Fragment与FragmentActivity的区别
- Fragment 和 FragmentActivity的使用
- 细说PHP(精要版)
- 有状态 vs 无状态
- 最长路问题
- Linux 下的免费桌面级杀毒软件
- 水木上的关于裁员的文章
- 【FragmentActivity】的简单实例
- C语言学习第十天(重要:C的灵魂)
- 使用cgroup限制java使用的内存量-思路
- [Python]网络爬虫(五):urllib2的使用细节与抓站技巧
- Eclipse, C++, 更改输出名称
- 基于FPGA的跨时钟域信号处理——专用握手信号
- 静态链接库LIB和动态链接库DLL的区别 创建和示例
- Linux网卡数据包的接收
- 杭电3123