简体   繁体   English

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

Here's a sample code of using spinner in android :这是在 android 中使用 spinner 的示例代码:

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我知道我们需要为适配器中的数据行指定布局

But why again using setDropDownViewResource() method.但是为什么再次使用setDropDownViewResource()方法。 I mean what does this function do and also tell me how it is different from the constructor of the ArrayAdapter .我的意思是这个函数做了什么,还告诉我它与ArrayAdapter的构造函数有何不同。

I have gone through the documentation, but didn't understand completely.我已经阅读了文档,但没有完全理解。

Here's is the difference - See below images这就是区别 - 见下图

simple_spinner_item simple_spinner_item

Simple_Spinner

If you're using your spinner with spinner.setAdapter(adapter);如果您将微调器与spinner.setAdapter(adapter); directly in your code, your spinner will looks like above image.直接在您的代码中,您的微调器将类似于上图。

But, if you're using adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);但是,如果您使用的是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.在您的代码中,它将显示您的微调器,如下图所示,其中微调器项目将显示单选按钮。

simple_spinner_dropdown_item simple_spinner_dropdown_item

在此处输入图像描述

Normally the difference between android.R.layout.simple_spinner_dropdown_item and android.R.layout.simple_spinner_item is通常 android.R.layout.simple_spinner_dropdown_item 和 android.R.layout.simple_spinner_item 之间的区别是

Simple spinner Dropdown view简单的微调器下拉视图

简单的微调器下拉视图

Simple spinner view简单的微调器视图

简单的微调视图

The difference is as below:区别如下:

  1. simple_spinner_item is the layout of each drop-down item on the spinner list. simple_spinner_item 是微调器列表中每个下拉项的布局。
  2. And inorder to house these x number of drop-down items, the layout required is simple_spinner_dropdown_item为了容纳这 x 个下拉项,所需的布局是 simple_spinner_dropdown_item

use adapter1.setDropDownViewResource(android.R.layout.select_dialog_singlechoice);使用 adapter1.setDropDownViewResource(android.R.layout.select_dialog_singlechoice);

  1. select_dialog_singlechoice -- to show radio button select_dialog_singlechoice -- 显示单选按钮
  2. select_dialog_multichoice --- multiple select select_dialog_multichoice --- 多选
  3. simple_spinner_dropdown_item --- without radio button simple_spinner_dropdown_item --- 没有单选按钮

just change this setDropDownViewResource line from above choice.只需从上面的选择中更改此 setDropDownViewResource 行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM