0

I am using a spinner with a custom adapter in my application. And depends on the selected item I want to call an API service. But API is not calling if I reselect the same item that is already currently selected. The element in the first position is hint text (Choose Item). So I have not called service on first item selection

 spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                    if (isNetworkAvailable()) {
                    
                        progressBar.setVisibility(View.VISIBLE);
                        getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
                                WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
                        try {
                            if (position == 0) {

                                progressBar.setVisibility(View.GONE);
                                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
                           

                                return;
                            } else {

                                
                                changePath(position, arrayitem.get(position));
                                
                            }

                        } catch (JSONException e) {
                            e.printStackTrace();
                          
                        }
                    }
                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {

                }
            });
Malhotra
  • 221
  • 3
  • 13
  • What you want can be easily done by kotlin `SharedFlow` and `DataBinding`, `SharedFlow` can react to same value assignment: https://stackoverflow.com/questions/65592423/stateflow-dont-emit-when-the-new-value-same-last-value – Sam Chen Sep 14 '21 at 15:19
  • @SamChen But i want it in Java – Malhotra Sep 14 '21 at 17:04

0 Answers0