How to define child views in a gallery via XML

A typical gallery view component application is similar to creating a ListView + ArrayAdapter workflow. Is there a way to get around this overhead by declaratively defining the gallery via XML?

<Gallery>
    <TextView text="Screen 1 - Swipe to Next screen"/>
    <TextView text="Screen 2 - Swipe to Prev screen"/>
</Gallery>

If this is not so, what is needed for work?

+3
source share
1 answer

It is not possible to define adapterView child views (Galler, Spinner, ListView, ...) directly in the layout XML file. as you did in your code.

However, there is a way to avoid adapters. However, it has limited usability. You can use the attribute android:entries.

<Gallery
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:entries="@array/my_items" >
</Gallery>

Put the reference to the array resource as the attribute value.

<string-array name="my_items">
        <item>text1</item>
        <item>text2</item>
        <item>...</item>
</string-array>

. , ( ) , . , .

+3

All Articles