Question

In my app I'm developing, I have a spinner in an alert dialog box.

The spinner works fine, but when I added the following lines to add the array to the spinner, my app crashing a few seconds after starting up:

    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.newFileTypeArray, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    newFileType.setAdapter(adapter);

What am I doing wrong?

These Android spinners seem to be a bit complicated as well, I don't think I'll be able to remember how to make them without referencing to the Android docs.

Was it helpful?

Solution

Problem solved.

I realised that the following line:

final Spinner newfiletypespinner = (Spinner) findViewById(R.id.newfiletypespinner);

I had to change to:

final Spinner newfiletypespinner = (Spinner) newFileDialogInflated.findViewById(R.id.newfiletypespinner);

With "newFileDialogInflated" being the previously inflated view so I could have a custom AlertDialog view:

final View newFileDialogInflated = View.inflate(this, R.layout.newfileview, null);

But thanks for the help!

OTHER TIPS

Hard to say for sure whether you've omitted it from your snippet or omitted it from your code, but do you initialize newFileType as a spinner?

Spinner newFileType = (Spinner)findViewById(R.id.newFileTypeSpinner);

or similar? If you're trying to set its adapter before initializing it, that would explain it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top