【问题标题】:Android: SQLite and ListViewsAndroid:SQLite 和 ListViews
【发布时间】:2010-12-18 01:47:08
【问题描述】:

首先,我发现了许多如何从数据库中获取数据并将其放入列表的示例,但这似乎是 ListActivites 的全部内容。

我的列表是 UI 的一部分,因此我不能使用 ListActivity,因为它不会占用整个屏幕(或者我可以吗?)。

这是用户界面:

<SlidingDrawer android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
   android:id="@+id/Drawer"
  android:orientation="vertical"
  android:handle="@+id/handle" 
   android:content="@+id/content">

<ImageView
android:id="@id/handle"
android:src="@drawable/tray_handle_normal"
android:layout_height="wrap_content" android:layout_width="wrap_content"/>

<RelativeLayout 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:id="@id/content" android:background="@color/black">


<ListView 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:id="@+id/List">
</ListView>

</RelativeLayout>

所以,从我读到的内容中,我需要从数据库中获取数据,然后将其放入某种数组中,然后使用数组适配器填充列表视图。那是对的吗?如果是这样,是否有一些示例代码,因为我只能找到与 ListActivites 相关的代码。

【问题讨论】:

    标签: database android sqlite listview


    【解决方案1】:

    您仍然可以使用 ListActivity。神奇的是将 ListView 的 id 设置为“@android:id/list”。但是,ListActivity 只是一种方便。您可以通过创建适配器(查看 ArrayAdapter 或 SimpleCursorAdapter)并手动将其连接到 ListView 来获得相同的结果。

    【讨论】:

    • 啊,我想知道如何使用列表活动。谢谢,这有点回答。就在发布解决方案之后,我发现了如何去做......它总是这样......!
    【解决方案2】:

    我认为您可以为此使用SimpleCursorAdapter

    我认为记事本教程使用它。如果您需要更复杂的东西,只需实现自己的视图适配器即可。这是sample code,它向您展示了如何做到这一点。

    【讨论】:

      猜你喜欢
      • 2012-06-09
      • 2012-09-11
      • 1970-01-01
      • 2013-04-18
      • 1970-01-01
      • 1970-01-01
      • 2011-01-02
      • 2010-10-09
      • 2020-02-25
      相关资源
      最近更新 更多