10.1
从fragment中启动activity
//启动CrimeActivity(CrimeListFragment.java)
删掉上面代码加上
Intent intent=new Intent(getActivity(),CrimeActivity.class);
startActivity(intent);
10.1.1附加extra信息
//创建newIntent方法(CrimeActivity.java)
private static final String EXTRA_CRIME_ID =
"com.bignerdranch.android.criminalintent.crime_id";
public static Intent newIntent(Context packageContext, UUID crimeId) {
Intent intent = new Intent(packageContext, CrimeActivity.class);
intent.putExtra(EXTRA_CRIME_ID, crimeId);
return intent;
}
//传递Crime实例(CrimeListFragment.java)
删掉原来的,加上下面代码
Intent intent = CrimeActivity.newIntent(getActivity(), mCrime.getId());
10.1.2获取extra信息
//获取extra数据并取得Crime对象(CrimeFragment.java)
删掉上面代码,加上下面的代码
UUID crimeId=(UUID) getActivity().getIntent()
.getSerializableExtra(CrimeActivity.EXTRA_CRIME_ID);
mCrime = CrimeLab.get(getActivity()).getCrime(crimeId);
10.1.3
//更新视图对象(CrimeFragemt.java)
mTitleField.setText(mCrime.getTitle());
mSolvedCheckbox.setChecked(mCrime.isSolved()
10.2
1.//编写newInstance(UUID)方法(CrimeFragment.java)
private static final String ARG_CRIME_ID = "crime_id";
public static CrimeFragment newInstance(UUID crimeId) {
Bundle args = new Bundle();
args.putSerializable(ARG_CRIME_ID, crimeId);
CrimeFragment fragment = new CrimeFragment();
fragment.setArguments(args);
return fragment;
}
2.//使用newInstance(UUID)方法(CrimeActivity.java)
将CrimeActivity.java删改为下图样式
UUID crimeId = (UUID) getIntent()
.getSerializableExtra(EXTRA_CRIME_ID);
return CrimeFragment.newInstance(crimeId);
10.2.2
1.将crimeFragmet.java删改成下图
UUID crimeId = (UUID) getArguments().getSerializable(ARG_CRIME_ID);
10.3
1.在CrimeLIstFragment.java添加下列代码
@Override
public void onResume() {
super.onResume();
updateUI();
}
if (mAdapter == null) {
} else { mAdapter.notifyDataSetChanged();
}