使用字符串数组填充Spinner

编程入门 行业动态 更新时间:2024-10-27 10:22:54
本文介绍了使用字符串数组填充Spinner的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在Android应用程序方面,我属于菜鸟联盟,我希望使用下面的数组或字符串(这是一个转换器应用程序)填充Spinner,这是我的XML文件的摘录,并且我希望填充微调框:

I'm in the rookie leagues when it comes to Android apps and am looking to populate a Spinner with an Array or strings (it's a converter app) below is an extract from my XML file and I'm looking to populate the the Spinner:

...... <string name="TemperatureString">Temperature</string> <string name="WeightString">Weight</string> <string name="VolumeString">Volume</string> <string name="SpeedString">Speed</string> <string name="LengthString">Length</string> <string name="AreaString">Area</string> <string name="EnergyString">Energy</string> <string name="PresureString">Presure</string> <string name="MemoryString">Memory</string> <string-array name="Convert_Type"> <item>@string/TemperatureString</item> <item>@string/WeightString</item> <item>@string/VolumeString</item> <item>@string/SpeedString</item> <item>@string/LengthString</item> <item>@string/AreaString</item> <item>@string/EnergyString</item> <item>@string/PresureString</item> <item>@string/MemoryString</item> </string-array>

据此,我正在尝试填充微调器(@+id/MainSpinner)-我不确定我在这里做什么,但是对于activity_main.xml我有以下内容:

From this, I'm trying to populate my spinner (@+id/MainSpinner) - I'm not sure what I'm doing here but for the activity_main.xml I have the following:

<Spinner android:layout_width="wrap_content" android:layout_height="match_parent" android:id="@+id/MainSpinner" tools:listitem="@layout/support_simple_spinner_dropdown_item"/>

我知道有一种通过Java做到这一点的方法,但我在Java方面更糟! 因此,如果可能,我希望将其保留在xml中.

I know there's a way of doing this via Java but I'm even worse at Java! For this reason, I'd like to keep this within xml if possible.

此外,如果有人可以向我指向一些链接,这些链接将带给我很棒的Java和xml技能-我从Udacity开始,发现它们很好,但是对于非IT人士来说,还有很多事情需要接受研究生(我从事金融工作,但发现这种事情真的很有趣!)

Also, If someone can want's to point me towards links to bring on my Java and xml skills that would be great - I've started with Udacity and have found them good but there's a lot to take in for a non-IT graduate (I work in finance but find this kinda thing really interesting!)

提前谢谢!

推荐答案

将ListView和Spinner控件与字符串数组绑定的最简单方法是

Simplest way to bind ListView and Spinner control with String Array is

android:entries = "@array/nameofarray"

<Spinner android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/MainSpinner" tools:listitem="@layout/support_simple_spinner_dropdown_item" android:entries="@array/Convert_Type"/>

如果要更改微调器的每个项目的主题,则将下面的样式放入res/values/styles.xml

If you want to change the theme of each item of Spinner then put below style into res/values/styles.xml

<style name="ItemTextAppearance"> <item name="android:textColor">#f00</item> <item name="android:textStyle">bold</item> <item name="android:typeface">monospace</item> </style>

和集合

android:theme="@style/ItemTextAppearance"

微调器.

更多推荐

使用字符串数组填充Spinner

本文发布于:2023-10-10 11:27:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1478535.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   字符串   Spinner

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!