I have a DialogFragment
on an Activity
class. This fragment has an EditText
field and all I want to do is check if the field has less than 3 digits on the input then show a toast message. App keeps crashing and I can't even see what exception it is throwing me in the LogCat/Stacktrace.
Activity Class:
public class ParentActivity extends AppCompatActivity{
public boolean getTextCodeLength(){
EditText editTextfield = (EditText)findViewById(R.id.textFieldName);
if(editTextfield.length() < 4)
{
return false;
}
return true;
}
}
Fragment Class:
public class EnterTextFragment extends DialogFragment {
public void onDialogOkClick(DialogInterface dialog) {
try {
15. boolean result = ((ParentActivity) getActivity()).getTextCodeLength();
if (result == false) {
Toast.makeText(myContext, "Code needs to be longer than 4 digits", Toast.LENGTH_LONG).show();
}
}
catch(Exception ex)
{
Log.e("YOUR_APP_LOG_TAG", "I got an error", ex);
}
//Perform some other functions
}
}
Whenever it hits the line marked with number 15
- it keeps crashing and I don't even get what's causing the error because I am unable to see any exceptions in the LogCat as mentioned. Some help would great be appreciated.
More Context: The toast is for testing purposes. Ideally I want to let the user stay on the fragment if their input is less than 4 digits.