Android Spinner 具有不同布局的“下拉状态"和“关闭状态"? [英] Android Spinner with different layouts for "drop down state" and "closed state"?

查看:48
本文介绍了Android Spinner 具有不同布局的“下拉状态"和“关闭状态"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的布局中有一个 Android Spinner 视图.我希望该微调器在关闭时仅显示一个文本项,但是当用户单击它时(即打开微调器对话框),我想为每个项目显示更广泛的信息,包括一个图标和一个附加的描述文本视图.就像现在一样,微调器在两种状态下都显示了完全相同的布局(图标、标题 + 描述).

I have an Android Spinner view in my layout. I would like that spinner to show only a single text item when closed, but when the user clicks on it (i.e. opens the spinner dialog) I would like to show more extensive information for each item, including an icon and an additional description text view. As it is now the spinner shows the very same layout (icon, title + description) in both states.

如果我将 ArrayAdapter 附加到微调器,那么我可以访问称为setDropDownViewResource"的东西,但这不一定是我需要的,因为我的微调器数据是从 Cursor 中获取的,而不是从任何类型的数组中获取的(我有,到目前为止,创建了我自己的适配器,扩展了 BaseAdapter).

If I attach an ArrayAdapter to the spinner, then I get access to something called "setDropDownViewResource" but that's not necessarily what I need, since my spinner data is fetched from a Cursor not from an Array of any kind (I have, as of now, created my own adapter, extending BaseAdapter).

谁能帮帮我?

推荐答案

你必须创建一个自定义的 Adapter 类用于 Spinner 并覆盖两个方法 getView() 用于正常关闭视图和 getDropDownView() 用于下拉列表视图.这两种方法都必须为单个元素返回一个 View 对象.

You have to create a custom Adapter class for the Spinner and overwrite the two methods getView() for the normal closed view and getDropDownView() for the drop down list view. Both methods must return a View object for a single element.

看看本教程 它可能会帮助您入门.

Have a look at this tutorial it might help you getting started.

这篇关于Android Spinner 具有不同布局的“下拉状态"和“关闭状态"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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