0

I am creating a DialogFragment that I use for my login dialog. I want to have autocompletion for the email addresses that are used as user ids. I found a good tutorial here, but it didn't really deal with using a DialogFragment.

My current code is:

DialogFragment dialog = new LoginDialogFragment();
AutoCompleteTextView emailLoginId = (AutoCompleteTextView) findViewById(R.id.login_user_id);
if (null == emailLoginId) {
    Log.d(tag, "EmailLoginId is null!");
}
// get list of drivers
ArrayAdapter<String> driverList = dbHelper.getAllDriverEmailStringAdapter();
Log.d(tag, "Driver List size is " + driverList.getCount());
emailLoginId.setAdapter(driverList);
dialog.show(getSupportFragmentManager(), "LoginDialogFragment");

As you can see, I'm creating the dialog, then attaching the list of names. Unfortunately, this gives me a null pointer exception on the line:

emailLoginId.setAdapter(driverList);

I'm sure this will probably be some embarrassingly simple oversight on my part, but that's okay, if it gets me moving forward.

I've tried this same code, with appropriate modifications, in the onStart() and onCreateView() portions of the LoginDialogFragment. In all cases, it can't find the fields, either the login id field, or the password field.

When calling from within the onStart() and onCreateView() routines, I used:

AutoCompleteTextView emailLoginId = (AutoCompleteTextView) getActivity().findViewById(R.id.login);

Is that wrong?

The only other thing I can figure that might be causing the problem is that the dialog isn't actually created until dialog.show(getSupportFragmentManager(), "LoginDialogFragment") is called, but that doesn't jibe with the documentation and you'd still think this would work in the onStart() routine at the very least.

Thanks, in advance, for your time.

Rben
  • 489
  • 1
  • 7
  • 18
  • a stack trace can help us help you! – Junseok Lee Jun 27 '13 at 01:04
  • Try and do this iinside `onCreateView` of Dialog Fragment. Worth a try. – Shobhit Puri Jun 27 '13 at 01:04
  • The stack trace doesn't give me much except to tell me the problem is null pointer exception on the emailLoginId.setAdapter(driverList) statement. The path used to get there seems all good. – Rben Jun 27 '13 at 13:42
  • I tried moving the code to onCreateView but I get the same result, it still nullpointers on the same line. What I get back from the findViewById is a null every time. I've double and triple checked, so I know that the id for the field is correct. I'm still scratching my head. – Rben Jun 27 '13 at 13:51
  • I'm no longer convinced this is some stupid mistake. I tried checking in each of the DialogFragment life cycle methods and I can't get access to the fields in any of them. I may have to rewrite this as a regular activity and just display it as a dialog, but that seems like a kludge. – Rben Jun 27 '13 at 15:41

0 Answers0