如何根据最近选择的微调器值动态更改文本框的值? [英] How to dynamically change the text box value according to the recently selected spinner value?

查看:140
本文介绍了如何根据最近选择的微调器值动态更改文本框的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是屏幕截图...我的微调器值更改仅在两次滑动后才会反映我有一个具有10个屏幕的应用程序,我的主要活动中有1个微调器,在片段中有一个文本框。我想在我的文本框中显示最近选择的微调器值。

Here is screenshot ...my changes in spinner value reflects only after 2 swipes I have an app with 10 screens and i have 1 spinner in my main activity and a textbox in fragment .I want to display the recently selected spinner value in my textbox .

我编写了一个代码,在文本框中显示选定的微调器值,该值在所有屏幕上都变得稳定。但是我不知道如何动态更改文本框值根据最近选择的微调器值。 (在拒绝投票之前,请为我提供一些解决方案

I wrote a code to display the selected spinner value in my text box and its become stable throughout all my screens.But i don't know how to dynamically change the text box value according to the recently selected spinner value. (Before downvoting kindly suggest me some solutions)

此处是获取微调器值的代码

Here is code to get the spinner value

String pos = (String) spinner.getSelectedItem();
        SharedPreferences sharedPref = getSharedPreferences("Mode", Activity.MODE_PRIVATE);
        SharedPreferences.Editor prefEditor = sharedPref.edit();
        prefEditor.putString("userChoicemode", pos);
        prefEditor.commit();

这里是检索它的代码

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

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

        modeselect.setText("" + get);


推荐答案

spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {

             textView.setText(spinner.getSelectedItem().toString());


            }

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

            }
        });

这篇关于如何根据最近选择的微调器值动态更改文本框的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆