gpt4 book ai didi

android - 在自定义 AlertDialog 中实现 Spinner

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:08:47 25 4
gpt4 key购买 nike

我正在尝试在自定义警报对话框中实现微调器,但我一直收到NullPointer 异常。有什么想法吗?

The NullPointer Exception occurs at the line: spinner.setAdapter(adapter); where spinner is null.

LayoutInflater inflater = getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.custom_dialog, (ViewGroup) findViewById(R.id.layout_root));
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(dialoglayout);

Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.priority_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);

builder.show();

最佳答案

dialoglayout 中搜索 Spinner

Spinner spinner = (Spinner) dialoglayout.findViewById(R.id.spinner);

关于android - 在自定义 AlertDialog 中实现 Spinner,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6020077/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com