多个项目中的android xml ids(列表类型)

时间:2011-12-28 19:13:05

标签: android android-layout

我目前有一个名为quests.xml的xml布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginTop="10dip">
        <Button
        android:id="@+id/btn_load_quests"
        android:layout_width="100dip"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginTop="15dip"
        android:layout_marginLeft="110dip"
        android:text="Load Quests" />
        <TextView
        android:id="@+id/quest_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="8pt"
        android:textColor="#FFFFFF"
        android:layout_alignParentLeft="true"
        android:text="buy 2 cups of coffee"/>
        <TextView
        android:id="@+id/quest_price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10pt"
        android:textColor="#00C322"
        android:layout_below="@id/quest_title"
        android:text="$25" />
        <TextView
        android:id="@+id/quest_points"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10pt"
        android:textColor="#1D81C1"
        android:layout_below="@id/quest_price"
        android:layout_alignParentLeft="true"
        android:text="25 pts" />
        <Button
        android:id="@+id/btn_select_quest"
        android:layout_width="100dip"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@id/quest_points"
        android:text="1" />
</RelativeLayout>

我想知道如何在多种情况下使用id(多个quest_titles等),就像列表一样。我从mysql加载数据,我想知道如何处理多行。基本上类似于css中的类。

1 个答案:

答案 0 :(得分:0)

如果从mysql加载数据,则需要一些适配器。您不需要多个ID,因为您会夸大多个视图,每个视图代表列表的一行。示例:http://sudarmuthu.com/blog/using-arrayadapter-and-listview-in-android-applications

如果您正在寻找等效的CSS,那么您应该阅读有关样式和主题的内容。有了它们,很容易让许多元素看起来都一样。

当遇到多个ID时,您无法在一个布局中使用多个ID。