0

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 1

Spinner 2:

Spinner 2

What is wrong with Spinner 2?

M.V.
  • 1,662
  • 8
  • 32
  • 55
  • try to give width as fill_parent in xml file for second spinner – Lavanya May 23 '11 at 12:28
  • still the same... is it possible that this happen because I use 2 spinners with the same definitions? – M.V. May 23 '11 at 12:33
  • @M.V. please look at this issue: http://stackoverflow.com/questions/21526982/how-to-create-spinner-to-show-current-and-next-30-dates – Sun Jun 30 '15 at 12:21

1 Answers1

1

You missed setDropDownResource()... for the second one....

一二三
  • 21,059
  • 11
  • 65
  • 74
ngesh
  • 13,398
  • 4
  • 44
  • 60