2

In my code spinnerObj.setSelection(count) dont work. I search it in google and dont find answer for me.

    count = 0;
    repairDetailsAdapter = new RepairDetailsAdapter(this, R.layout.gas_station_spinner_item, details);
    detailsOptionSpinner.setAdapter(repairDetailsAdapter);
    for (RepairDetail detail : details) {
        if (detail.getId() == tempDetail.getId()) {
            detailsOptionSpinner.setSelection(count);
            detailsOptionSpinner.invalidate();
            break;
        }
        count++;
    }

This lines (from stackOverFlow) dont work:

 final int finalCount = count;
new Handler().postDelayed(new Runnable() {
    public void run() {
        detailsOptionSpinner.setSelection(finalCount);
        detailsOptionSpinner.invalidate();
    }
}, 13);
Soham
  • 4,397
  • 11
  • 43
  • 71
MyNameIs
  • 832
  • 1
  • 8
  • 19

1 Answers1

3

Have you tried to set the spinner by using two arguments, the second using a boolean:

detailsOptionSpinner.setSelection(finalCount, true); 

From the developers page it shows:

setSelection(int position, boolean animate)
//Jump directly to a specific item in the adapter data.
Ranjithkumar
  • 16,071
  • 12
  • 120
  • 159