gpt4 book ai didi

java - 警报对话框内的微调器和按钮 onClick 返回 NullPointerException

转载 作者:太空狗 更新时间:2023-10-29 13:16:15 26 4
gpt4 key购买 nike

我在 AlertDialog 中(在 FAB 中)有 Spinner NPE

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// custom dialog
final Dialog dialog = new Dialog(MainActivity.this);
dialog.setContentView(R.layout.share_dialog_layout);

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

ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_spinner_item, itemname);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // The drop down view
spinner.setAdapter(spinnerArrayAdapter);

Button dialogButton = (Button) dialog.findViewById(R.id.dlgButtonOK);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});

dialog.show();
}
});

有人知道这个问题吗?

我以某种方式能够让它显示出来,但它是空的。

最佳答案

尝试改变

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

Spinner spinner = (Spinner) dialog.findViewById(R.id.dlgSpinner);

关于java - 警报对话框内的微调器和按钮 onClick 返回 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34444460/

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