@Override public void onCrimeSelected(Crime crime) { if (findViewById(R.id.detail_fragment_container) == null) { Intent pagerIntent = CrimePagerActivity.newIntent(CrimeListActivity.this, crime.getId()); startActivity(pagerIntent); } else { Fragment newDetail = CrimeFragment.newInstance(crime.getId()); getSupportFragmentManager() .beginTransaction() .replace(R.id.detail_fragment_container, newDetail) .commit(); } }
/** * Check to see if item from menu was selected then proceeds properly depending on item selected. * * @param item item from the menu options * @return if the actions were performed properly */ @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { // to add a new crime case R.id.fragment_crime_list_menu_item_new_crime: // Create and add new crime Crime crime = new Crime(); CrimeLab.get(getActivity()).addCrime(crime); // Create intent to start a new instance of CrimePagerActivity Intent intent = CrimePagerActivity.newIntent(getActivity(), crime.getId()); startActivity(intent); return true; // to show subtitles and hide "Show Subtitle" option case R.id.fragment_crime_list_menu_item_show_subtitle: mSubtitleVisible = !mSubtitleVisible; // make option invisible/visible getActivity().invalidateOptionsMenu(); updateSubtitle(); return true; default: return super.onOptionsItemSelected(item); } }
@Override public void onListItemClick(ListView l, View v, int position, long id) { Crime c = (Crime) getListAdapter().getItem(position); Log.d(TAG, c.getTitle() + " was clicked"); Intent i = new Intent(getActivity(), CrimePagerActivity.class); i.putExtra(CrimeActivityFragment.EXTRA_CRIME_ID, c.getId()); startActivity(i); }
// Starting a new CrimeActivity by calling newIntent from CrimeActivity @Override public void onClick(View v) { mPreviousAdapterSelected = getAdapterPosition(); Intent intent = CrimePagerActivity.newIntent(getActivity(), mCrime.getId()); startActivity(intent); }