我一直試圖在片段內顯示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);
}
}
感謝
你應該只是有一個功能,顯示在該片段中的呼叫活動的對話片段 - 使用FragmentInteractionListener模式,谷歌放入其樣板碎片/活動代碼。聽起來就像它試圖顯示對話框,雖然 –
把InfoDialogFragment代碼在這裏 –
我們可以看到InfoDialogFragment代碼? – Gudin