android.R.layout.simple_spinner_dropdown_item和android.R.layout.simple_spinner_item的区别 [英] Difference between android.R.layout.simple_spinner_dropdown_item and android.R.layout.simple_spinner_item

查看:1567
本文介绍了android.R.layout.simple_spinner_dropdown_item和android.R.layout.simple_spinner_item的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是Android中使用微调样品code:

Here's a sample code of using spinner in android :

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

我已经明白,我们需要在适配器指定数据行的布局

I have understood that we need to specify a layout for the datarows in the adapter

但是,为什么再次使用 setDropDownViewResource()方法。我的意思是什么呢这个功能做的,还告诉我,它是如何从构造不同的 ArrayAdapter

But why again using setDropDownViewResource() method. I mean what does this function do and also tell me how it is different from the constructor of the ArrayAdapter.

我已经通过文件了,但并没有完全理解。

I have gone through the documentation, but didn't understand completely.

推荐答案

这里的区别 - 请参阅下面的图片

Here's is the difference - See below images

如果您使用的微调与 spinner.setAdapter(适配器); 直接在code,你的微调会看起来像上面的图片。

If you're using your spinner with spinner.setAdapter(adapter); directly in your code, your spinner will looks like above image.

不过,如果你使用 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 在code,它会显示你的微调像下面的图片,其中的微调项目将显示为单选按钮。

But, if you're using adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); in your code, it'll show your spinner like below image where the spinner items will shown with radio buttons.

这篇关于android.R.layout.simple_spinner_dropdown_item和android.R.layout.simple_spinner_item的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆