A hands-on Android project designed to teach students how to use the ArrayAdapter class to create dependent Dropdown menus (Spinners).
This application mimics a simplified E-commerce filter. It demonstrates the logic of "Cascading Selectors":
- User selects a Brand (e.g., Samsung).
- App detects the selection via a Listener.
- App dynamically updates the second dropdown to show only relevant models (e.g., S24, S23).
By studying this code, students will learn:
- ArrayAdapter: How to bridge data from
strings.xmlto UI components. - Android Resources: Organizing static data in
res/values/strings.xmlusing<string-array>. - Event Handling: Implementing
OnItemSelectedListenerto trigger actions. - Conditional Logic: Switching adapters based on array index positions.
We store the data in static arrays to keep the Java code clean.
<string-array name="Mobile">
<item>Apple</item>
<item>Samsung</item>
</string-array>
<string-array name="apple">
<item>iPhone 15</item>
<item>iPhone 14</item>
</string-array>