开发者

Problems with creating spinner

开发者 https://www.devze.com 2023-01-14 23:40 出处:网络
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 开发者_开发知识库fe

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.


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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消