简体   繁体   English

Android中简单的硬编码ListView

[英]Simple hard coded ListView in Android

Is it possible to do something like this in Android? 是否可以在Android中执行类似的操作? (basically the equivalent of select and option in HTML): (基本上等同于HTML中的selectoption ):

<ListView android:layout_height="match_parent"
    android:layout_width="match_parent">
        <ListViewItem>TEST</ListViewItem>
        <ListViewItem>TEST1</ListViewItem>
</ListView>

I have tried this, it obviously doesn't work. 我已经试过了,显然不起作用。 All I can find online is information about using adapters, but as I have some hard coded values I don't need to use an adapter - I'm happy to put it directly in the XML file. 我在网上只能找到有关使用适配器的信息,但是由于我有一些硬编码值,因此不需要使用适配器-我很乐意将其直接放在XML文件中。

Is this possible? 这可能吗?

1 ] Create a String array in strings.xml 1]在strings.xml中创建一个String数组

2 ] Use the following attribute inside Listview tag android:entries="@array/your_array_name" 2]在Listview标记android中使用以下属性:entries =“ @ array / your_array_name”

Done ! 完成!

否在android中是不可能的,但是使用android:entries属性使用String资源数组加载列表项。

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

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