I'm currently learning Android Java. I am trying to understand the
use of spinners. I would like to create two spinners that use the
same data - select one responses for each spinner. In the book I
purchased, it shows example code how to create a spinner. How could I
add another spinner using example below.?
I can see a new arrayAdapter called aa is bound to the list data, I
can also see the methods for aa that select the data or leave it
blank. I can see the textView label where data is stored from spinner,
and I can see the spinner is called spin.
If I create a new spinner called spin2, a new textView label called
selection2, bind arrayAdapter aa2 to array items, the program does not
work. I also tried putting a new textView and spinner into the
main.xml file. The end result was not as expected. If anyone can point
me in the right direction I would be most grateful.
Many thanks.
example code below:
public class SpinnerDemo extends Activity
implements AdapterView.OnItemSelectedListener {
TextView selection;
String[] items={"lorem", "ipsum", "dolor", "sit",
"amet","consectetuer", "adipiscing", "elit"};
String[] items2 ={"morbi", "vel","ligula", "vitae", "arcu",
"aliquet", "mollis"};
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
selection=(TextView)findViewById(R.id.selection);
Spinner spin=(Spinner)findViewById(R.id.spinner);
spin.setOnItemSelectedListener(this);
ArrayAdapter<String> aa=new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item,items);
aa.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(aa);
}
public void onItemSelected(AdapterView<?> parent,
View v, int position, long id) {
selection.setText(items[position]);
}
public void onNothingSelected(AdapterView<?> parent) {
selection.setText("");
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---