Click here to Skip to main content
15,665,942 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
there is a spinner in main activity and 1 text box in task is to change the value of text box according to the recently selected spinner code works well.but the textbox changes its state only after 2 swipes.I don't know y this lagging me out

here is my code in main activity

spinner = (Spinner)findViewById(;
        final ArrayAdapter<String> dataAdapter1 = new ArrayAdapter<>(this,android.R.layout.simple_spinner_item,array2);

        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                String pos = (String) spinner.getSelectedItem();
                SharedPreferences sharedPref = getSharedPreferences("Mode", Activity.MODE_PRIVATE);
                SharedPreferences.Editor prefEditor = sharedPref.edit();
                prefEditor.putString("userChoicemode", pos);
            public void onNothingSelected(AdapterView<?> parent) {

my fragment code :

final TextView modeselect = (TextView) view.findViewById(;

        final SharedPreferences sharedPref = this.getActivity().getSharedPreferences("Mode", Activity.MODE_PRIVATE);
        String get = sharedPref.getString("userChoicemode",selected);

        modeselect.setText("" + get);

What I have tried:

i have tried using
but it doesn't works.
David Crow 12-Sep-17 11:42am    
Have you considered calling registerOnSharedPreferenceChangeListener() in your fragment?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900