jeudi 24 janvier 2019

Android Spinner create and infinite loop?

I am new to android ad i tried to create a spinner to change the language inside the app through localehelper and i had to use recreate method for the app to reload with the appropriate string resources But the spinner created an infinite loop and keep calling the recreate method over and over and refreshing the activity here is the code for it languageSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){

        @Override
        public void onItemSelected(AdapterView adapter, View v, int i, long lng) {
            int mNumber =0;
           if(i==0){
               LocaleHelper.setLocale(MainActivity.this,mLanguageCodeEn);
               recreate();
               mNumber=1;
           }else if(i==1){
               LocaleHelper.setLocale(MainActivity.this, mLanguageCodeAr);
               recreate();
               mNumber=0;
           }
           if(mNumber ==1){
               languageSpinner.setSelection(0,false);
           }else if (mNumber ==0){
               languageSpinner.setSelection(1,false);
           }
        }

        @Override
        public void onNothingSelected(AdapterView arg0) {
        }
    });

i tried to find a way around this issue and use a variable (mNumber) to cause the onItemSelected to be ignored if mNumber matches the value in that the if statement assign to it but that didnt work

Aucun commentaire:

Enregistrer un commentaire