我想创建一个片段,它将静态菜单显示为列表中的一组行。
我喜欢在表视图中使用静态单元格的iOS方法。我如何在android中实现这一点(所以不需要代码来定义元素,只需要xml)
接下来有没有什么常规的方法来定义xml中的静态元素?
(伪代码)
list_view.xml
<List view>
- use element my_row with onclick=row1_clicked and title="row 1"
- use element my_row with onclick=row2_clicked and title="row 2"
- use element my_row with onclick=row3_clicked and title="row 3"
- use element my_row with onclick=row4_clicked and title="row 4"
</List view>
my_row.xml
<My Row>
- text field (title should go here)
- on click (on click should go here)
</My Row>所以基本上我想在列表中“包含”行,并在xml级别上(不需要代码)。
发布于 2012-12-17 22:42:17
不幸的是,禁止通过xml定义列表视图。相反,需要乱七八糟的适配器。
发布于 2014-05-27 14:24:28
可以使用字符串数组来取得一些进展,例如,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/sports_array"/>
</LinearLayout>与…结合
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="sports_array">
<item>Shuttle Badminton</item>
<item>Tennis</item>
<item>FootBall</item>
</string-array>
</resources>来源:http://theopentutorials.com/tutorials/android/listview/android-creating-and-populating-listview-items-in-xml/
发布于 2013-07-09 01:13:49
您可以使用嵌套在ScrollView中的垂直LinearLayout来获得所需的内容。将您的" listview“项放入LinearLayout中,并使它们看起来像listview的元素。
如果您一定要使用ListView (例如,您正在使用ListFragment),那么您必须使用ListAdapter子类,或者使用您自己的子类。
https://stackoverflow.com/questions/13864260
复制相似问题