2016-12-21 16 views
1

フラグメント内にDialogFragmentを表示しようとしましたが、成功しませんでした。ここに私のコード:それの断片が画面に表示されているときはいつでもフラグメント内にDialogFragmentを表示

@Override 
public void onResume() { 
    super.onResume(); 
    Log.d(TAG, "onResume"); 
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); 
    if (user != null && !user.isEmailVerified()) { 
     InfoDialogFragment dialog = new InfoDialogFragment(); 
     dialog.show(getActivity().getSupportFragmentManager(), "InfoDialogFragment"); 
    } 
} 

は、画面が暗くなると、私は、画面をタッチすると、それは通常、コントラストを取り戻すが、私は、ダイアログの断片を見ることはできません。 私は何が欠けていますか?ここ

はDialogFragmentためのコードである:

public class InfoDialogFragment extends DialogFragment { 
private InfoDialogListener listener; 

@Override 
public void onAttach(Context activity) { 
    super.onAttach(activity); 
    // Verify that the host activity implements the callback interface 
    try { 
     // Instantiate the InfoDialogListener so we can send events to the host 
     listener = (InfoDialogListener) activity; 
    } catch (ClassCastException e) { 
     // The activity doesn't implement the interface, throw exception 
     throw new ClassCastException(activity.toString() 
       + " must implement DeleteListListener"); 
    } 
} 

@Override 
public Dialog onCreateDialog(Bundle savedInstanceState) { 
    // Use the Builder class for convenient dialog construction 
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 
    // Get the layout inflater 
    LayoutInflater inflater = getActivity().getLayoutInflater(); 
    View layout = inflater.inflate(R.layout.fragment_info, null); 

    TextView message = (TextView) layout.findViewById(R.id.message); 
    message.setText(getActivity().getString(R.string.user_not_verified)); 
    // 
    Button ok = (Button) layout.findViewById(R.id.ok_button); 
    ok.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      listener.onDialogOKClick(InfoDialogFragment.this); 
     } 
    }); 
    return builder.create(); 
} 


public interface InfoDialogListener { 
    void onDialogOKClick(DialogFragment dialog); 

} 

}

おかげ

+0

- FragmentInteractionListenerパターングーグルを使いますボイラープレートの断片/活動コードに入れます。 –

+0

InfoDialogFragment code hereを入力してください –

+1

InfoDialogFragmentコードを表示できますか? – Gudin

答えて

3

使用getChildFragmentManager代わりにgetActivity().getSupportFragmentManager()。これらは異なるインスタンスです。

+0

これは非常に重要です。ありがとうございました。フラグメントからchildFragmentManagerを使用する必要があります – j2emanue

0

実際、私はInfoDialogFragmentクラスのコード行が欠落していました。

builder.setView(layout); 

これを理解するには2日かかりました。 あなたの答えをありがとう。

0

あなたのInfoDialogFragmentクラスのコンストラクタを作成することができますし、このようにそれを表示することができます:あなたはちょうどフラグメントの呼び出し側の活動のダイアログの断片を示して機能を持っている必要があり

DialogFragment newFragment = new SelectDateFragment(NextDate); 
newFragment.show(getFragmentManager(), "DatePicker"); 
関連する問題