I need help passing data from my parent activity to a dialog. I am trying to set text on a longclick.
public boolean onLongClick(View v) {
RememberLongPressedButton(v);
String buttonText = GetButtonText(v);
DialogFragment newFragment = new SomeDialogFragment();
newFragment.show(getFragmentManager(), _APPNAME);
if(!(buttonText.equals(" ") || buttonText.isEmpty()))
DataToEditText(newFragment,buttonText);
return true;
}
The code for the Dialog fragment class
public class SomeDialogFragment extends DialogFragment {
public interface SomeDialogFragment {
void onDialogPositiveClick(DialogFragment dialog);
void onDialogNegativeClick(DialogFragment dialog);
}
private SomeDialogFragmentListener _listener;
@Override
public void onAttach(Context context) {
super.onAttach(context);
try {
if(context instanceof SomeDialogFragmentListener)
_listener = (SomeDialogFragmentListener) context;
} catch (ClassCastException e) {
// The activity doesn't implement the interface, throw exception
throw new ClassCastException(context.toString()
+ " must implement SomeDialogFragmentListener");
}
}
My app crashes when i call this line
Dialog dialog = dialogFragment.getDialog();
EditText editText = (EditText) dialog.findViewById(R.id.dialog_text);