使用数组适配器实现可扩展列表

时间:2014-05-27 10:15:53

标签: android

我试图实现从网站下载的预制库,以便在我的listview中使用它。它被称为可扩展列表视图,我想我们都知道那是什么。但是在它的xml文件中,它的listview是这样的:

<?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="vertical">
<RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

    <TextView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/text"
            android:text="Hello World"/>

    <!-- this is the button that will trigger sliding of the expandable view -->
    <Button
            android:id="@+id/expandable_toggle_button"
            android:text="More"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/text"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@id/text"/>

</RelativeLayout>

<!-- this is the expandable view that is initially hidden and will slide out when the 
more button is pressed -->
<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal"
        android:id="@+id/expandable"
        android:background="#000000">

    <!-- put whatever you want in the expandable view -->
    <Button
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="0.5"
            android:text="Action A" />

    <Button
            android:id="@+id/details"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="0.5"
            android:text="Action B"/>

</LinearLayout>
</LinearLayout>

但是我们都知道数组列表需要listview只需要textview才能工作,否则它会抛出异常,有人可以指导我这些东西如何在数组列表上工作吗?感谢

1 个答案:

答案 0 :(得分:1)

您可以使用自定义适配器。有关如何使用的教程,请参阅此link。 :)

相关问题