标签:version log 列表 1.0 title java strong new apt
这次我们做的是一个记录生活坏习惯的应用
这是他完成后的界面样子
首先我们创建一个fragment事务
if (fragment == null) {
? fragment = new CrimeFragment();
? fm.beginTransaction()
? .add(R.id.fragment_container, fragment)
? .commit();
这是它的布局文件
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; } }
最后我们为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();
}
});
标签:version log 列表 1.0 title java strong new apt
原文地址:http://www.cnblogs.com/haiou123/p/7616504.html