Android Spinner: onItemSelected listener is not called when selecting the same item

后端 未结 2 895
情深已故
情深已故 2021-01-22 14:16

I have a requirement to show an AlertDialog when selecting the 2nd item in Spinner. I know that using onItemSelected we can listen to the

2条回答
  •  暖寄归人
    2021-01-22 14:23

    try the code below:

    spinner.setOnItemSelectedListener(this);
    
    @Override
    public void onItemSelected(AdapterView arg0, View arg1, int arg2, long arg3) 
    {
         switch(arg2)
         {
              case 0:
              {
                   Dialog dialog = new Dialog(getApplicationContext());
                   .......
                   dialog.show();
                   spinner.setSelection(0);
              }
              break;
         }
    [...]
    

提交回复
热议问题