I have defined 2 spinners:
<Spinner android:layout_width="fill_parent" android:layout_marginRight="10dp" android:layout_height="wrap_content" android:id="@+id/spinnerOd" android:layout_marginLeft="10dp" android:layout_below="@+id/OD"></Spinner>
<Spinner android:layout_below="@+id/DO" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/DO" android:layout_alignRight="@+id/DO" android:id="@+id/spinnerDo"></Spinner>
Next there is a code to populate both Spinners with the same data (They are used to select date range and data is the same)...
Spinner sOd = (Spinner)findViewById(R.id.spinnerOd);
Spinner sDo = (Spinner)findViewById(R.id.spinnerDo);
final sOdDATA items[] = new sOdDATA[9];
long Today = System.currentTimeMillis();
for (int i = 0; i < 9; i++) {
long makeDate = Today + ((i - 1)*(24*60*60*1000));
SimpleDateFormat thisDateFormater = new SimpleDateFormat("dd.MM.yyyy");
SimpleDateFormat dayFormater = new SimpleDateFormat("E");
String SloDay = "";
if(thisDateFormater.format(makeDate).equals(thisDateFormater.format(Today)))
{
SloDay = "Danes";
}
else
{
if(thisDateFormater.format(makeDate).equals(thisDateFormater.format(Today - ((24*60*60*1000)))))
{
SloDay = "Včeraj";
}
else
{
if(thisDateFormater.format(makeDate).equals(thisDateFormater.format(Today + ((24*60*60*1000)))))
{
SloDay = "Jutri";
}
else
{
SloDay = returnSLODayName(dayFormater.format(makeDate));
}
}
}
thisDateFormater.format(makeDate);
items[i] = new sOdDATA(SloDay + ", " + thisDateFormater.format(makeDate) ,thisDateFormater.format(makeDate).toString());
}
ArrayAdapter<sOdDATA> adapter =
new ArrayAdapter<sOdDATA>(
this,
android.R.layout.simple_spinner_item,
items );
adapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
sOd.setAdapter(adapter);
sOd.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view,
int position,
long id) {
sOdDATA d = items[position];
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
ArrayAdapter<sOdDATA> adapterDo =
new ArrayAdapter<sOdDATA>(
this,
android.R.layout.simple_spinner_item,
items );
adapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
sDo.setAdapter(adapterDo);
sDo.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view,
int position,
long id) {
sOdDATA d = items[position];
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
And my result is next:
Spinner 1:
Spinner 2:
What is wrong with Spinner 2?