开发者

Implementing a Spinner inside a Custom AlertDialog

I am trying to implement a spinner inside of a custom alertdialog box, but I keep getting a NullPointer Exception. any ideas?

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_dr开发者_如何转开发opdown_item);
        spinner.setAdapter(adapter);

        builder.show();


Search for Spinner in dialoglayout

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


Please provide a stacktrace so we may know WHERE your Nullpointer exception occurs :) .

Cheers,

Ready4Android

P.s. Grrr seems I cant write comments :O otherwise this would have been a comment.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜