13

そこで、この手法でダイアログとして表示されるDialogFragmentを作成しました

これで起動し、このポップアップ内でユーザーが操作したときに、別のフラグメントをこのダイアログにスライドさせたいと思います。FragmentTransaction.add()を介してこれを実行しようとしています。ここで、このレイアウトのコンテナーの1つのIDを指定します。この時点で私は次のようになります。

java.lang.IllegalArgumentException: No view found for id 0x7f09013f for fragment <fragmentClassThatIWasPushingIn>

簡単なテストとして、ダイアログではなくメインのバッキングアクティビティ内のコンテナIDにプッシュしようとしましたが、問題なく機能しました。

DialogFragmentsとそのコンテナIDについて、FragmentTransactionsを許可しないものはありますか?

一時的なものとして、現在のDialogFragmentを非表示にしてこの新しいフラグメントを表示するようにトランザクションに指示しましたが、アニメーション/表示が少し不快なので、この問題を解決したいと思います。

ありがとう

4

4 に答える 4

17

aDialogFragmentがaとして表示されている場合、Dialogそれは実際にFragmentはコンテナビューでは実際のものではありません。Fragmentこれは、基本的にのラッパーであるコンテナレスDialogです。

いいえ、Fragment内部を表示することはできませんFragmentDialog。あなたが本当にこれをしたいのなら、私はあなたがそれから追加することができるように新しいActivityスタイルを作成するのが最善の方法だと思います。DialogFragments

于 2011-04-09T20:08:34.677 に答える
3

alexanderblomはDialogFragmentダイアログとして機能するのは正しいですが、フラグメントとして機能させることができます。setShowsDialog(false);

結局、次のことが私のために働いた:

ファイル:res / layout / wifidirect_dialog_wifidirect:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/dialog_wifidirect_layout">

    <LinearLayout
        android:id="@+id/frag_container"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:orientation="vertical" >

            <!-- This is replaced during runtime -->
            <RelativeLayout
                android:id="@+id/frag_list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="top" >
            </RelativeLayout>
    </LinearLayout>

    <!-- The Cancel Button -->
    <View
    android:layout_width="fill_parent"
    android:layout_height="1dp"
    android:layout_marginBottom="0dp"
    android:background="?android:attr/dividerVertical" />
    <Button
         android:id="@+id/dialog_wifidirect_cancel"
         style="?android:attr/buttonBarButtonStyle"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:text="@string/cancel"/>         
</LinearLayout>

ファイルsrc/.../WifiDirectDialog.java:

public class WiFiDirectDialog extends DialogFragment  {
        public static final String TAG = "WifiDirectDialog";
        public static final String DEVICE_LIST_FRAGMENT_TAG = "WIFIDIRECT_DEVICE_LIST_FRAGMENT";


        public static WiFiDirectDialog newInstance(){                 
             WiFiDirectDialog wDialog = new WiFiDirectDialog();
             //We want this Dialog to be a Fragment in fact,
             //otherwise there are problems with showing another fragment, the DeviceListFragment
             wDialog.setShowsDialog(false);
             //wDialog.setStyle(SherlockDialogFragment.STYLE_NORMAL,android.R.style.Theme_Holo_Light_Dialog);
             //We don't want to recreate the instance every time user rotates the phone
             wDialog.setRetainInstance(true);
             //Don't close the dialog when touched outside
             wDialog.setCancelable(false);
             return wDialog;
        }


        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            Log.v(TAG,"onCreateView");

            View view = inflater.inflate(R.layout.wifidirect_dialog_wifidirect,container, false);

            //Log.v(TAG,"FragmentTransaction started");            
            ListFragment listFragment = new YourListFragment();

            FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
            transaction.addToBackStack(DEVICE_LIST_FRAGMENT_TAG)
                .replace(R.id.frag_list,deviceListFragment,DEVICE_LIST_FRAGMENT_TAG)
                .commit();
            //Log.v(TAG,"FragmentTransaction finished");

            return view;
        };

        @Override
        public void onActivityCreated(Bundle savedInstanceState){
            Log.v(TAG,"onActivityCreated");
            super.onActivityCreated(savedInstanceState);

            Dialog dialog = getDialog();
            dialog.setTitle(R.string.wifidirect_dialog_title);

            // Set button listeners etc...///
            Button cancelButton = (Button) view.findViewById(R.id.dialog_wifidirect_cancel);
            cancelButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {                
                    dismiss();
                }
            });
        }
于 2014-03-06T11:15:55.723 に答える
1

onCreateViewメソッドでわかるように、実際にはコンテナがあります。コンテナを使用してビューを作成します。

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle icicle) {
    Log.d(TAG, "onCreateView");
    View v = inflater
            .inflate(R.layout.move_folder_dialog, container, false);

FragmentManagerがコンテナを取得できないようです。

これはバグでしょうか?

于 2011-12-28T11:43:46.500 に答える
1

commitAllowingStateLoss()を使用してDialogFragmentを表示します

DialogFragment.show(FragmentManager manager、String tag)には、状態の喪失を許可しながらダイアログを表示するオプションがありません。DialogFragment.dismissAllowingStateLoss()があるため、少し奇妙で一貫性がありません。

ただし、いつでもDialogFragmentトランザクションを手動でコミットするか、次のようなヘルパーメソッドを作成できます。

public static void showDialogAllowingStateLoss(FragmentManager fragmentManager, DialogFragment dialogFragment, String tag) {
FragmentTransaction ft = fragmentManager.beginTransaction();
ft.add(dialogFragment, tag);
ft.commitAllowingStateLoss();
}
于 2020-01-02T08:41:58.840 に答える