安卓:填充表数据的数组 [英] Android: Populating a table with an array of data
问题描述
欲设置具有列的固定量,和行与第一行列出每个列的内容的X量的表。例如,一列将是'姓名'和第二列将是'年龄',那么将有哪些存储数据的行的X量。有没有我可以为这个数据设置阵列其他地方,并自动创建/与此数据填充表的行的任何方式。我使用的是自定义适配器pviously这样做$ P $一个更简单的例子,但我不太清楚如何去这所涉及的表。我很卡住,任何帮助将大大AP preciated,感谢,将
I want to set up a table which has a fixed amount of columns, and an X amount of rows with The first row listing the contents of each column. For example, one column will be 'Name' and a second column will be 'Age', then there will be an X amount of rows which store the data. Is there any way that I can set up arrays for this data elsewhere, and automatically create/fill the rows of the table with this data. I've done this previously with a more simple example using a Custom Adapter but I'm not quite sure how to go about this with a table involved. I'm quite stuck and any help would be greatly appreciated, thanks, will
推荐答案
A 的ListView
基本上充当任何数据表中的一行。您应该创建与所有你想在一行中显示属性的POJO。您可以创建为数据创建一个自定义XML的布局,这可能是由一个水平的LinearLayout
对应于您的列。
A ListView
basically acts as a row within any table of data. You should create a POJO with all the attributes you want to display in a row. You can create create a custom xml layout for the data, which would probably by a horizontal LinearLayout
that corresponds to your columns.
POJO
public class MyData {
public String Name;
public int Age;
// More data here
}
ListView项布局(layout_list_item.xml)
ListView item layout (layout_list_item.xml)
<?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="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/Name"
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="0.7" />
<TextView
android:id="@+id/Age"
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="0.3" />
</LinearLayout>
主要布局
<?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">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="0.7"
android:text="Name" />
<TextView
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="0.3"
android:text="Age" />
</LinearLayout>
<ListView
android:id="+@id/MyDataListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
然后,您需要这台场与来自您的POJO值列表视图自定义适配器。有很多在互联网上教程这一点。
You then need a custom adapter which sets the fields in the list view with the values from your POJO. There are plenty of tutorials on the internet for this.
这篇关于安卓:填充表数据的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!