Android的 - 完全由XML创建列表视图 [英] Android - creating listview entirely from xml

查看:246
本文介绍了Android的 - 完全由XML创建列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想present在我的应用程序的一些选择。 现在我做的按钮之一的另一回事。

我真正希望做的是present他们为在设置应用程序,如清单。 这可以归结为创建具有predefined值/选项列表。 我的问题是,我无法弄清楚如何使用XML做到这一点。 我可以添加ListView控件到XML是这样的:

< ListView的机器人:ID =@ + ID / ListView01机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< / ListView控件>

但我怎么添加条目呢? 我发现所有的例子都做编程方式 - 通过鼠标适配器或阵列适配器

如何创建textViews只有N- Android的使用XML列表? 没有人知道它是如何在设置应用程序,都做了什么?

谢谢!

解决方案
  

但我怎么添加条目呢?所有   我发现的例子做   编程 - 通过游标   适配器或阵列适配器。

使用了安卓项属性的的ListView 元素,指向一个&LT ;字符串数组> 资源(通常放在 RES /价值/ arrays.xml

I want to present some choices in my application. Right now I'm doing it with buttons one under another.

What I really want to do is to present them as a list like in "Settings" application. This boils down to creating a list with predefined values/choices. My problem is that I can't figure out how to do it with xml. I can add ListView to xml like this:

<ListView android:id="@+id/ListView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></ListView>

But how do I add entries to that? All examples I've found do it programatically - through cursor adapters or array adapters.

How do I create a list of textViews using XML only n Android? Does anyone know how it's done in "Settings" application and alike?

Thanks!

解决方案

But how do I add entries to that? All examples I've found do it programatically - through cursor adapters or array adapters.

Use the android:entries attribute on your ListView element, pointing to a <string-array> resource (typically put in res/values/arrays.xml).

这篇关于Android的 - 完全由XML创建列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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