1

我有一个 Horizo​​ntalScollView。它有一个 LinearLayout 孩子。由于无法将 SimpleCursorAdapter 绑定到它(显然),如何使用基于数据库内容创建的子项填充线性布局?

我试过了:

    SimpleCursorAdapter summaryItems = new SimpleCursorAdapter(this, R.layout.summary_item, summaryItemsCursor, from, to);
    int count  = summaryItems.getCount();
    View new_view;
    for (int i = 0; i < count; i++) {
        new_view = (summaryItems.newView(this, summaryItemsCursor, mNewsContainer));
        mNewsContainer.addView(new_view);
    }

我希望 SimpleCursorAdapter.newView() 返回的视图可以使用,但显然不行。我对android很陌生,完全不知道正确的方法。

XML 供参考:

<HorizontalScrollView android:id="@+id/news_gallery"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
        <LinearLayout android:id="@+id/news_container"
            android:orientation="horizontal"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            >
        </LinearLayout>
</HorizontalScrollView>

和 summary_item

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/news_gallery_item"
    android:layout_marginRight="@dimen/news_gallery_item_spacing"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <ImageView android:id="@+id/news_gallery_item_image"
        android:adjustViewBounds="true"
        android:maxHeight="@dimen/news_gallery_image_height"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <TextView android:id="@+id/news_gallery_item_tagline"
    style="@style/news_gallery_text_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>
</FrameLayout>
4

2 回答 2

1

这听起来(并且看起来)就像您想要使用ListView. 可以在此处找到教程。

要填充ListView,您可以使用SimpleCursorAdapter.


由于您需要水平使用它,因此您可以使用HorizonatalListView-class,它是用户创建的普通扩展ListView(因此您可以使用它的所有方法)。相应的问题可以在这里找到。

于 2011-10-06T08:29:51.133 回答
0

在您的项目视图上带有 Inflater 的 ViewBinder 应该可以解决问题

于 2011-10-06T10:05:51.023 回答