Android开发-Crimina

犀渠玉剑良家子,白马金羁侠少年。这篇文章主要讲述Android开发-Crimina相关的知识,希望能为你提供帮助。
这次我们做的是一个记录生活坏习惯的应用
这是他完成后的界面样子

Android开发-Crimina

文章图片

首先我们创建一个fragment事务
if (fragment == null) { ?fragment = new CrimeFragment(); ?fm.beginTransaction() ?.add(R.id.fragment_container, fragment) ?.commit();

  这是它的布局文件
< ?xml version="1.0" encoding="utf-8"?>
< FrameLayout
【Android开发-Crimina】xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent" android:layout_height="match_parent"/>
创建Crime类
public class Crime { private UUID mId; private String mTitle; private Date mDate; private boolean mSolved; public Crime() { mId = UUID.randomUUID(); mDate = new Date(); }public UUID getmId() { return mId; }public String getmTitle() { return mTitle; }public void setmTitle(String mTitle) { this.mTitle = mTitle; }public Date getmDate() { return mDate; }public void setmDate(Date mDate) { this.mDate = mDate; }public boolean ismSolved() { return mSolved; }public void setmSolved(boolean mSolved) { this.mSolved = mSolved; }}

使用ViewPager
  • 最后我们为UI添加Vi额为Pager,让用户可以左右滑动屏幕,切换查看不同列表项的明细页面
  • 创建CrimePagerActivity
···
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_crime_pager); }
···
-设置pager adapter
···
mViewPager = (ViewPager) findViewById(R.id.crime_view_pager);
mCrimes = CrimeLab.get(this).getCrimes(); FragmentManager fragmentManager = getSupportFragmentManager(); mViewPager.setAdapter(new FragmentStatePagerAdapter(fragmentManager){@Override public Fragment getItem(int position){ Crime crime = mCrimes.get(position); return CrimeFragment.newInstance(crime.getId()); }@Override public int getCount(){ return mCrimes.size(); } });

 






    推荐阅读