I have a HorizontalScollView. It has a LinearLayout child. How do I populate the linear layout with children created based on content from a database since I can’t bind a SimpleCursorAdapter to it (obviously)?
I’ve tried:
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);
}
I was hoping that the view returned by the SimpleCursorAdapter.newView() would be usable, but apparently not. I’m quite new to android and completely lost as to the right way to do this.
XML’s for reference:
<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>
and 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>
This sounds (and somehow looks) like you’ll want to use a
ListView. A tutorial might be found here.To populate the
ListView, you can then use aSimpleCursorAdapter.Since you need it horizontally, you can use the
HorizonatalListView-class, which is a user-created extension to a normalListView(so you can use all it’s methods). The corresponding question can be found here.