I emulated what I thought was pretty standard Dialogcode:
public class DChooseSeparator extends DialogFragment
{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
builder
.setTitle("My Title")
.setView(myDialogLayout)
.setPositiveButton(getString(R.string.sOKButton), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if(myEditText.getText().toString().equals(""))
{
Toast.makeText(getActivity(), "enter something!", Toast.LENGTH_SHORT).show();
}
else { myListener.onSet(myEditText.getText().toString()); }
}
})
.setNegativeButton(getString(R.string.sCancelButton), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
return builder.create();
}
}
And in onStart Fragment, which shows this:
sepButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MyDialog myDialog = new MyDialog();
myDialog.show(getFragmentManager(), "tMyDialogTag");
myDialog.getButton(Dialog.BUTTON_POSITIVE).setEnabled(false);
}
}
However, this does not work, since the function is getButtonnot available for mine DialogFragment. I also cannot do this in the class DialogFragment, as I need to first show().
So ... where exactly can / should it be disabled Button? Do I really need to move the entire method creation Dialogto a method onClick?
Thank you in advance for your help.
source
share