我有一个 HorizontalScollView。它有一个 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>