如何清除微调器中的选定位置?

问题描述 投票:-1回答:1

因为用户可以从微调器中的位置跳转;我有类似的东西:

   public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
   switch ((int) parent.getSelectedItemId()){
            case 0:
                car = 1;
                motor = 0;
                break;
            case 1:
               // HERE I want clear case 0;
                bike = 1;
                motor = 0;
                // here car should be 0 again but the value is 1
                break;
            case 2:
               // HERE I want clear case 1 and case 0;
                bus = 1
                motor = 0;
                // here car and bike should be 0 again but the value is both 1
                break;
            default:
            motor = 1;
    }
}

我认为开关循环在这里很好。如何清除每个单独的案件?还尝试了:Clear Spinner on Button presshow to clear spinner value in androidandroid spinner - how do I remove the current selection?也许我应该解决这个问题吗?

android position spinner clear
1个回答
0
投票

您可以使用Spinners setSelection属性将Spinner重置为其原始位置。

spinner.setSelection(position);

默认值是指0索引处的值。那么应该是

spinner.setSelection(0);
© www.soinside.com 2019 - 2024. All rights reserved.