简体   繁体   English

如何在XML文件中将列表打印为按钮? (Android)

[英]How do I make a list be printed as buttons in the xml file? (Android)

I want to make a loop that in my main.xml creates a button for each item in the list. 我想做一个循环,在main.xml中为列表中的每个项目创建一个按钮。 But I cant see a way to loop in the xml file and create more buttons that way. 但是我看不到在xml文件中循环并以此方式创建更多按钮的方法。

main.xml can't be changed by your program, any more than your Java source files. 除了您的Java源文件外,您的程序无法更改main.xml

What are you actually trying to do? 您实际上想做什么? Provide UI for a list? 提供列表用户界面? Take a look at ListAdapter . 看一下ListAdapter

There is no loop syntax for the xml layout. xml布局没有循环语法。 If it will be dynamic you have to do it programmatically. 如果它是动态的,则必须以编程方式进行。

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

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