Dropdown box android layout code

To create dropdown box in android java layout,

1. Create dropdown values as string-array in strings.xml

<string name="spinner_title">Select Category</string> <string-array name="category_array"> <item>Automobile</item> <item>Business</item> <item>Realestate</item> <item>Services</item> <item>BuyandSell</item> <item>Travel</item> <item>Jobs</item> </string-array>

2. Create following spinner element in your layout to use above dropdown values for dropdown boxes

<!-- Spinner Element --> <Spinner android:id="@+id/catSpinner" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_margin="5dp" android:layout_marginTop="10dp" android:layout_below="@id/catText" android:entries="@array/category_array" android:textAppearance="?android:attr/textAppearanceLarge" android:prompt="@string/spinner_title" />
Sign In or Register to comment.