I tried to create a DialogFragment dialog box that could be canceled when listening, after some searching, I decided to go with this implementation:
public class ErrorDialogFragment extends RoboDialogFragment { private static final String MESSAGE_ARG = "message"; private TextView text; public ErrorDialogFragment newInstance (String message){ ErrorDialogFragment f = new ErrorDialogFragment(); Bundle args = new Bundle(); args.putString(MESSAGE_ARG, message); f.setArguments(args); return f; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.error_dialog_fragment, container, false); v.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ErrorDialogFragment.this.dismiss(); } }); text = (TextView) v.findViewById(R.id.error_dialog_text_textView); text.setText(getArguments().getString(MESSAGE_ARG)); return v; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setStyle(DialogFragment.STYLE_NO_TITLE, 0); }
A special message can be configured in the alert dialog box and will be rejected when clicked.
What do you think is the best way to achieve this?
Thanks.
android android-fragments dialog
Goofyahead
source share