How to disable onItemSelectedListener to be invoked when setting selected item by code

后端 未结 12 1186
慢半拍i
慢半拍i 2021-02-02 08:05

Just wondering how you handle the following problem: a result is calculated depending on two spinners\' selected items. To handle the UI things, i.e. a user picks a new item in

12条回答
  •  太阳男子
    2021-02-02 08:23

    First add boolean values for stopping spinner listener call

      Boolean check = false;
    

    Then you add on Touch listener and on Item click Listener Like below code

     holder.filters.setOnTouchListener(new View.OnTouchListener() {
                   @Override
                   public boolean onTouch(View v, MotionEvent event) {
    
                       check = true;
                       return false;
                   }
               });
    
               holder.filters.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
               {
    
                   @Override
                   public void onItemSelected(AdapterView parent, View arg1, int position, long id)
                   {
                       flag = filterids.get(position);
    
                       if(check)
                       {
                           check = false;
                           new Applyfilters().execute(flag,"3");
                       }else{
    
                       }
    
                   }
    
                   @Override
                   public void onNothingSelected(AdapterView arg0)
                   {
                       // TODO Auto-generated method stub
                   }
               });
    

    Its simple working good for stopping server call multiple times.

提交回复
热议问题