关于Android应用程序,我属于菜鸟联盟,我希望使用下面的数组或字符串(这是一个转换器应用程序)填充Spinner,这是我的XML文件的摘录,并且我希望填充Spinner:
......
Temperature
Weight
Volume
Speed
Length
Area
Energy
Presure
Memory
@string/TemperatureString
@string/WeightString
@string/VolumeString
@string/SpeedString
@string/LengthString
@string/AreaString
@string/EnergyString
@string/PresureString
@string/MemoryString
由此,我试图填充我的微调器(@+id/MainSpinner)-我不确定我在这里做什么,但是对于activity_main.xml我有以下几点:
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中。
此外,如果有人希望向我指向一些链接,这些链接将带给我很棒的Java和xml技能-我从Udacity开始,发现它们很好,但是对于非IT毕业生来说,我有很多收获( 从事金融工作,但发现这种事情真的很有趣!)
提前致谢!
Oracle有很棒的Java教程。 只是谷歌" Java教程"。 这将是第一击。
将ListView和Spinner控件与字符串数组绑定的最简单方法是
android:entries ="@array/nameofarray"
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
#f00
bold
monospace
和集合
android:theme="@style/ItemTextAppearance"
微调器。
如何获得点击微调器项目的价值?
使用setOnItemSelectedListener和spinner.getSelectedItem().toString()
我想获得价值,而不是名字
使用ArrayList和ArrayAdapter。 欲了解更多stackoverflow.com/a/37046661/6840733
在Spinner标签中使用entrys属性
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/MainSpinner"
android:entries="@array/Convert_Type"
tools:listitem="@layout/support_simple_spinner_dropdown_item"/>