Android的限制没有在微调的下拉列表中显示的项 [英] Android limit the no of items displayed in a spinner's dropdown list

查看:97
本文介绍了Android的限制没有在微调的下拉列表中显示的项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有必然可能有0或多个项目在任何时候数组适配器微调的项目。我想微调下拉列表中只显示三个项目的时间,被滚动的其余项目。 我已经试过包装的微调有一个固定的宽度,但微调布局内的下拉列表中仍然占据了整个屏幕(如果有,在阵列适配器许多项目),以显示列表。

I have a spinner item bound to an array adapter which might have 0 or more items at any time. I want the spinner dropdown list to only show three items at a time, the rest of the items being scrollable. I have tried wrapping the spinner within a layout with a fixed width but the spinner drop down list still takes up the entire screen(if there are that many items in the array adapter) to display the list.

推荐答案

我一直在寻找在微调源$ C ​​$ C,它好像你不能这样做即用旋涂器。

I was looking at the Spinner source code and it seems like you can't do that with a spinner.

微调有其称为自己的专用接口 SpinnerPopup ,它定义了如何下拉菜单项可以显示。这是目前的基础上 spinnerMode 允许一个下拉或对话框的列表。

The Spinner has its own private interface called SpinnerPopup which defines how dropdown items can be shown. This is currently based on the spinnerMode allowing for a dropdown or dialog list.

这两个选项也是微调类作为私有类内部实现的: DialogPopup DropdownPopup 。既然你不能访问他们,在我看来,你唯一的选择,在这一点上是:

Both options are also implemented inside the Spinner class as private classes: DialogPopup and DropdownPopup. Since you can't access them, it seems to me your only options at this point are:

  1. 基于其他部件,如这个例子实现自定义的微调。
  2. <一个href="https://android.googlesource.com/platform/frameworks/base/+/2888524e03896831f487e5dee63f18f1c33c0115/core/java/android/widget/Spinner.java"相对=nofollow>从微调类,它似乎pretty的自包含复制code 和实现你的一个微调的版本它,修改任何你喜欢的吧。
  1. Implement your own custom spinner based on other widgets such as in this example.
  2. Copy the code from the Spinner class which seems pretty self-contained and implement your version of a spinner with it, modifying whatever you like in it.

我很抱歉,我不能有更多的帮助。

I'm sorry I couldn't be of more help.

祝你好运!

编辑:

如果您选择选项2,我认为,所有你需要做的就是添加你的模式实施 SpinnerPopup 接口。然后构造函数中的微调(上下文的背景下,的AttributeSet ATTRS,INT defStyle,INT模式)另一个情况添加到开关检查模式来实例化自己的弹出窗口。似乎不难。

If you choose option 2, I think all you need to do is add your mode implementing the SpinnerPopup interface. Then inside the constructor Spinner(Context context, AttributeSet attrs, int defStyle, int mode) add another case to the switch checking for the modes to instantiate your own popup. Doesn't seem hard.

这篇关于Android的限制没有在微调的下拉列表中显示的项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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