I have this code:
package lijap.app.starcraft2counters;
import java.io.File;
import android.app.Activity;
import android.os.Bundle;
import android.os.Enviro
You could share the adapter between different Spinner
s if they adapted the same information. Clearly each of your adapters need to adapt a different set of String
s, so you need to create an ArrayAdapter
for each Spinner
.
A single OnItemSelectedListener
will work for the 3 Spinners
(as long as you set them). You can call getId()
on the AdapterView<?>
passed as an argument to know which Spinner
raised the event.
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
switch(arg0.getId()){
case R.id.s_answertime:
break;
case ...
}
}
Check this one
yearDropdown.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id)
{
selectedyear = parentView.getSelectedItemPosition();
drpyear = yearDropdown.getSelectedItem().toString();
//your code here
}
public void onNothingSelected(AdapterView<?> parentView)
{
selectedyear = 0;
//return;
}
});
monthDropdown.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id)
{
//your code here
}
public void onNothingSelected(AdapterView<?> parentView)
{
selectedmonth = 0;
//return;
}
});
dayDropdown.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id)
{
//your code here
}
public void onNothingSelected(AdapterView<?> parentView)
{
selectedday = 0;
}
});
you need to create each adapter for every spinner.
adapterYear = new ArrayAdapter<CharSequence>(this,android.R.layout.simple_spinner_item);
yearDropdown.setAdapter(adapterYear);
adapterMonth = new ArrayAdapter<CharSequence>(this,android.R.layout.simple_spinner_item);
monthDropdown.setAdapter(adapterMonth);
adapterDays = new ArrayAdapter<CharSequence>(this,android.R.layout.simple_spinner_item);
dayDropdown.setAdapter(adapterDays);