实现自定义AlertDialog内微调 [英] Implementing a Spinner inside a Custom AlertDialog
本文介绍了实现自定义AlertDialog内微调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想实现一个自定义alertdialog箱内部的微调,但我不断收到一个空指针异常...任何想法?
注:空指针异常发生在行:spinner.setAdapter(适配器);
其中,微调为null。
LayoutInflater吹气= getLayoutInflater();
查看dialoglayout = inflater.inflate(R.layout.custom_dialog,(ViewGroup中)findViewById(R.id.layout_root));
AlertDialog.Builder建设者=新AlertDialog.Builder(本);
builder.setView(dialoglayout); 微调微调=(微调)findViewById(R.id.spinner);
ArrayAdapter<&CharSequence的GT;适配器= ArrayAdapter.createFromResource(
对此,R.array.priority_array,android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(适配器); builder.show();
解决方案
在dialoglayout搜索微调
微调微调=(微调)dialoglayout.findViewById(R.id.spinner);
对不起,死灵。没有留意日期...
I am trying to implement a spinner inside of a custom alertdialog box, but I keep getting a NullPointer Exception... any ideas?
Note: 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();
解决方案
Search for Spinner in dialoglayout
Spinner spinner = (Spinner) dialoglayout.findViewById(R.id.spinner);
Sorry for necro. Not paid attention to the date...
这篇关于实现自定义AlertDialog内微调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文