Created
February 28, 2011 03:58
-
-
Save julianshen/846914 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Helper function to show the details of a selected item, either by | |
* displaying a fragment in-place in the current UI, or starting a | |
* whole new activity in which it is displayed. | |
*/ | |
void showDetails(int index) { | |
mCurCheckPosition = index; | |
if (mDualPane) { | |
// We can display everything in-place with fragments. | |
// Have the list highlight this item and show the data. | |
getListView().setItemChecked(index, true); | |
// Check what fragment is shown, replace if needed. | |
DetailsFragment details = (DetailsFragment) | |
getFragmentManager().findFragmentById(R.id.details); | |
if (details == null || details.getShownIndex() != index) { | |
// Make new fragment to show this selection. | |
details = DetailsFragment.newInstance(index); | |
// Execute a transaction, replacing any existing | |
// fragment with this one inside the frame. | |
FragmentTransaction ft | |
= getFragmentManager().beginTransaction(); | |
ft.replace(R.id.details, details); | |
ft.setTransition( | |
FragmentTransaction.TRANSIT_FRAGMENT_FADE); | |
ft.commit(); | |
} | |
} else { | |
// Otherwise we need to launch a new activity to display | |
// the dialog fragment with selected text. | |
Intent intent = new Intent(); | |
intent.setClass(getActivity(), DetailsActivity.class); | |
intent.putExtra("index", index); | |
startActivity(intent); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment