public class DetailsFragment extends Fragment{private static final String[] WEEKS=new String[]{"a-1","b-1","c-1"};public static DetailsFragment newInstance(int index){DetailsFragment f = new DetailsFragment();Bundle b = new Bundle();b.putInt("index", index);f.setArguments(b);System.out.println("--==");return f;}public int getShowIndex(){int index = getArguments().getInt("index",0);return index;}@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {TextView text = new TextView(getActivity());text.setText(WEEKS[getShowIndex()]);return text;}}
Public class FragmentAcitivity extends ListFragment {private static final String [] WEEKS = new String [] {"a", "B", "c "}; // set the initialization selection position int mCurCheckPosition = 0; int mShownCheckPosition =-1;/*** fill data */@ Overridepublic void onActivityCreated (Bundle savedInstanceState) {super. onActivityCreated (savedInstanceState); setListAdapter (new ArrayAdapter
(GetActivity (), android. r. layout. simple_list_item_activated_1, android. r. id. text1, WEEKS); // The showDetals (mCurCheckPosition) of the selected row by default at creation;} @ Overridepublic void onListItemClick (ListView l, View v, int position, long id) {super. onListItemClick (l, v, position, id); // manually select a row to display the details of the row showDetals (position );} /*** display details ** @ param index selected row */public void showDetals (int index) {// fragment manager FragmentManager am = GetFragmentManager (); DetailsFragment details = (DetailsFragment) am. findFragmentById (R. id. details); if (details = null | details. getShowIndex ()! = Index) {// set the single-choice mode getListView (). setChoiceMode (ListView. CHOICE_MODE_SINGLE); // getListView () is selected for the specified entry (). setItemChecked (index, true); details = DetailsFragment. newInstance (index); // The New DetailsFragment instance FragmentTransaction ft = am. beginTransaction (); // replace FrameLayout with DetailsFragmentft. setTransition (FragmentTransaction. TRANSIT_FRAGMENT_FADE); // Replace the obtained fragment with the content of the current ViewGroup. If you do not replace the value of add, the value of ft is accumulated at one time. replace (R. id. details, details); // submit ft. commit ();}}}
<frameLayout android:id="@+id/details" android:layout_weight="2" android:layout_width="0dp" android:layout_height="match_parent" android:background="?android:attr/detailsElementBackground"/>