It will helps in creating a dynamic drop down in the xml(i.e for font end) and helps in selecting the particular item in the dropdown dynimally. For dynamic selection of items in dropdown the code is written in .java file
<?xml version="1.0" encoding="utf-8" ?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Spinner android:id="@+id/spinner" android:layout_width="wrap_content" android:layout_height="wrap_content" android:prompt="@string/account_prompt" android:minWidth="180px" android:layout_below="@+id/accimage" /> <?xml version="1.0" encoding="utf-8" ?> <resources> <string name="hello">Hello World, PersonActivity!</string> <string name="app_name">P2P</string> <string name="account_prompt">Select Account</string> <string-array name="accounts_array"> <item>Saving Account</item> <item>Current Account</item> <item>Demat Account</item> </string-array> </resources>
//.java file::: For dynamic selection on items in dropdown import android.view.View; import android.widget.AdapterView; import android.widget.Toast; import android.widget.AdapterView.OnItemSelectedListener; public class SpinnerActivity implements OnItemSelectedListener { @Override public void onItemSelected(AdapterView<?> PersonActivity, View view, int pos, long id) { Toast.makeText(PersonActivity.getContext(), "The acounts" + PersonActivity.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show(); } @Override public void onNothingSelected(AdapterView<?> PersonActivity) { //Do nothing } }