2013-09-16 2 views
0

사용자 정의 커서 어댑터를 통해 목록보기를 표시하고 목록보기 항목을 클릭하면 세부 정보를 표시하는 탭 탐색 기능이있는 작업 표시 줄을 사용하는 앱이 있습니다. 가로 모드 일 때 이중 창을 표시하고 세로 모드 인 경우 부모/자식 뷰를 표시하는 논리를 구현했습니다.Android : 방향 변경시 화면 새로 고침

내 방향은 방향을 변경하면 항목을 선택하거나 다른 탭으로 변경하기 전까지는 조각이 그대로 유지된다는 것입니다.

IE : 가로에서 세로로 변경하면 이중 창이 세로 모드로 표시됩니다.

제 질문은 조각을 강제로 다시로드하는 것입니다. 나는 onStop()과 onResume()을 실험했지만, 거기에서 어떤 메소드를 호출해야하는지 모르겠습니다.

도움이나 의견을 크게 주시면 감사하겠습니다.

public class ItemListFragment extends ListFragment { 

// initialize variables 
private boolean mDualPane; 
private int mCurCheckPosition = 0; 
private DataAdapter db; 
private Cursor cursor; 
private MyListAdapter items; 

// methods 
@Override 
public View onCreateView(LayoutInflater inflater, 
     ViewGroup container, Bundle savedInstanceState) { 
    return inflater.inflate(R.layout.fragment_layout, container, false); 
} 

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

    // create a database connection 
    db = new DataAdapter(getActivity()); 
    db.open(); 
    cursor = db.getAllRecords(); 

    // get the filter EditText view 
    filterText = (EditText) getActivity().findViewById(R.id.search_box); 
    filterText.addTextChangedListener(filterTextWatcher); 

    // set the parameters for the ListAdapter 
    String[] from = new String[] { DataAdapter.KEY_TITLE }; 
    int[] to = new int[] {R.id.item_title }; 

    // Now create an array adapter and set it to display using our row 
    items = new MyListAdapter(getActivity(), R.layout.item_cell, cursor, from, to); 

    // get the listview 
    ListView listview = getListView(); 
    listview.setAdapter(items); 

    // check if we need dual pane 
    mDualPane = isLandscape(); 

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

    if (mDualPane) { 
     // getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE); 
     items.setSelectedPosition(mCurCheckPosition, cursor); 
    }  
} 

\ 레이아웃 \의 Fragment_layout.xml :

<?xml version="1.0" encoding="utf-8"?> 

<ListView 
    android:id="@android:id/list" 
    android:layout_width="match_parent" 
    android:layout_height="0dip" 
    android:layout_weight="1" /> 

\ 레이아웃 토지 \의 fragment_layout.xml 여기

내 ListFragment입니다 :

<?xml version="1.0" encoding="utf-8"?> 

<ListView 
    android:id="@android:id/list" 
    android:layout_width="match_parent" 
    android:layout_height="0dip" 
    android:layout_weight="1" /> 

<FrameLayout 
    android:id="@+id/details" 
    android:layout_width="0px" 
    android:layout_height="match_parent" 
    android:layout_weight="1" /> 

당신이 당신의 매니페스트에서 일부 구성을 필요로하는 모든의

답변

0

첫째;

<activity 
     android:name="yourActivity" 
     android:configChanges="orientation|screenSize"  
     android:screenOrientation="sensor" > 
    </activity> 

실제로이 구성은 가로 및 세로 모드를 자동으로 처리합니다. 그러나 프래그먼트의 특정 변경 사항을 원하면 액티비티의 onConfigurationChanged 메소드에서 프래그먼트의 메소드를 트리거 할 수 있습니다.

public void onConfigurationChanged(Configuration newConfig) { 
    super.onConfigurationChanged(newConfig); 

    // Checks the orientation of the screen 
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { 
     //TODO with Landscape 
    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { 
     //TODO with Portrait 
    } 
} 
+0

응답 해 주셔서 감사합니다. 내 매니페스트에 추가 속성을 추가했지만 여전히 동일한 동작을 얻습니다. 조각을 강제로 다시로드하려면 onConfigurationChanged 메서드에 무엇을 넣어야합니까? – wyoskibum

관련 문제