In main.xml I would like to have a spinner1 with two radio buttons and a spinner2 with 3 checkboxes. I don't know how to define and create this spinners in Main.java. Need some help.
main.xml
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Spinner
android:id="@id/spinner2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
spinner1 - needs to have radio buttons and spinner2 need to have multiple checkboxes
main.java
privare Spinner spiner1,spiner2;
public void OnCreate(BUndle SaveInstaceState)
{
super.OnCreate(savedInstanceState);
setContentView(R.layout.main)
spiner1=(Spinner)findViewById(R.id.spinner1);
spiner2=(Spinner)findViewById(R.id.spinner2);
//what to do from here?
}
create a strings.xml file in res/values/ and add the following:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="spinnerstr">Choose an item</string>
<string-array name="spinner_array">
<item>apple</item>
<item>orange</item>
<item>grapes</item>
</string-array>
In your spinner.java, add the followoing:
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.spinner_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
Hope this will help you.