0

カスタムカーソルアダプターを介してリストビューを表示し、リストビューアイテムをクリックすると詳細データを表示するタブナビゲーション付きのアクションバーを利用するアプリがあります。横向きモードではデュアル ペインを表示し、縦向きモードでは親子ビューを表示するロジックを実装しました。

私の問題は、向きを変更しても、アイテムを選択するか別のタブに変更するまでフラグメントが同じままであることです。

IE: 横向きから縦向きに変更すると、デュアル ペインが縦向きモードで表示されます。

私の質問は、フラグメントを強制的にリロードするにはどうすればよいですか? onStop() と onResume() を試してみましたが、そこからどのメソッドを呼び出すべきかわかりません。

どんな助けや提案も大歓迎です。

ここに私のListFragmentがあります:

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);
    }       
}

\layout\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" />

\layout-land\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" />

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

4

1 に答える 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
    }
}
于 2013-09-16T13:39:20.933 に答える