Code example for ListFragment

Methods: getListView, getActivity, getArguments, getFragmentManager

		return f;
	public int getShownIndex() { 
		return getArguments().getInt("index", 0);
	public int getPreviousFragmentId() { 
		return getArguments().getInt("prevFragmentId", sId);
	public void onActivityCreated(Bundle savedInstanceState) {
		int previousFragmentId = getPreviousFragmentId();
		sId = ++previousFragmentId;
		if (savedInstanceState != null) {
			// Restore last state for checked position. 
			mCurCheckPosition = savedInstanceState.getInt("curChoice", 0);
		// In dual-pane mode, list view highlights selected item. 
		// Populate list with static array of titles. 
		if(numberOfCardOnDeck % 2 == 0){
			setListAdapter(new MyCustomAdapter(getActivity(), 0, Shakespeare.TITLES,Color.BLACK));
			setListAdapter(new MyCustomAdapter(getActivity(), 0, Shakespeare.TITLES2Planet,Color.BLACK));
	public void onSaveInstanceState(Bundle outState) {
		outState.putInt("curChoice", mCurCheckPosition);
	public void onListItemClick(ListView l, View v, int position, long id) {
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = super.onCreateView(inflater, container, savedInstanceState);
		return view;
	 * 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. 
	private void showDetails(int index) {
		mCurCheckPosition  = index;
		// 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. 
		DataViewFragment details = (DataViewFragment) getFragmentManager().findFragmentById(sId);
		if (details == null || details.getShownIndex() != index) {			
			// Make new fragment to show this selection. 
			details = DataViewFragment.newInstance(index, sId);
			// Execute a transaction, replacing any existing 
			// fragment with this one inside the frame. 
			FragmentTransaction ft = getFragmentManager().beginTransaction();
			ft.replace(sId, details);
			StackScrollView stackScrollView = ((RootViewController)getActivity()).getStackScrollView();
			stackScrollView.addViewInSlider(details, false);
			ft = null;
			stackScrollView = null;
Stop searching for code, let great code find you!  Add Codota to your java IDE