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 fragment.my task is to change the value of text box according to the recently selected spinner value.my code works well.but the textbox changes its state only after 2 swipes.I don't know y this lagging happening.help me out

here is my code in main activity

spinner = (Spinner)findViewById(R.id.spinner2);
        final ArrayAdapter<String> dataAdapter1 = new ArrayAdapter<>(this,android.R.layout.simple_spinner_item,array2);
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(dataAdapter1);
        spinner.invalidate();

        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                //dataAdapter1.notifyDataSetChanged();
                Toast.makeText(getApplicationContext(),"well",Toast.LENGTH_LONG).show();
                String pos = (String) spinner.getSelectedItem();
                SharedPreferences sharedPref = getSharedPreferences("Mode", Activity.MODE_PRIVATE);
                SharedPreferences.Editor prefEditor = sharedPref.edit();
                prefEditor.putString("userChoicemode", pos);
                prefEditor.commit();
            }
            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });



my fragment code :

final TextView modeselect = (TextView) view.findViewById(R.id.pass);

        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
dataAdapter1.notifyDataSetChanged();
but it doesn't works.
Posted
Comments
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