2011-09-14 15 views

答えて

1

ListFragmentその例では、/選択したリスト項目を作成するListFragmentのonActivityCreated方法でgetListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);getListView().setItemChecked(index, true);を使用していますここで、indexはローカル変数から取得され、デフォルトでは0に設定されています。だからあなたのようなものを持っていると思います:

public static class TitlesFragment extends ListFragment { 
    boolean mDualPane; 
    int mCurCheckPosition = 0; 

    @Override 
    public void onActivityCreated(Bundle savedInstanceState) { 
     super.onActivityCreated(savedInstanceState); 

     // Populate list with our static array of titles. 
     // (Replace this with your own list adapter stuff 
     setListAdapter(new ArrayAdapter<String>(getActivity(), 
      android.R.layout.simple_list_item_activated_1, Shakespeare.TITLES)); 

     if (savedInstanceState != null) { 
      // Restore last state for checked position. 
      mCurCheckPosition = savedInstanceState.getInt("curChoice", 0); 
     } 

     getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE); 
     getListView().setItemChecked(mCurCheckPosition, true); 
    } 

    @Override 
    public void onSaveInstanceState(Bundle outState) { 
     super.onSaveInstanceState(outState); 
     outState.putInt("curChoice", mCurCheckPosition); 
    } 

    // ... the rest of the ListFragment code .... 
} 

は、私が先頭ににリンクされている例を見て、それはあなたを取得し、実行している必要があります!

関連する問題