微调价值变动 [英] Spinner on value Change

查看:115
本文介绍了微调价值变动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个微调在我的系统。现在,我不得不改变取决于第一微调值的第二微调的选定值。只要用户将改变第一离心器的值,该第二离心器值将自动设置根据第一离心器的选择的值。如何实现这一点?

解决方案

您好微调教程:

  

现在创建一个实现AdapterView.OnItemSelectedListener嵌套类。这将提供一个项目时已选定的微调,将通知您的应用程序回调方法。下面是这个类应该是这样的:

 公共类MyOnItemSelectedListener实现OnItemSelectedListener {

    公共无效onItemSelected(适配器视图<>父,
        视图中查看,INT POS,长I​​D){
      Toast.makeText(parent.getContext()),这颗行星是+
          parent.getItemAtPosition(POS)的ToString(),Toast.LENGTH_LONG).show();
    }

    公共无效onNothingSelected(适配器视图父){
      // 没做什么。
    }
}
 

  

在AdapterView.OnItemSelectedListener需要onItemSelected()和onNothingSelected()回调方法。当从适配器视图中的项目被选择前者被调用,在这种情况下,一个短消息吐司显示选定的文本;后者被称为当选择从适配器视图,其中不会发生在这种情况下消失,因此它被忽略。   现在MyOnItemSelectedListener需要被施加到微调。返回到的onCreate()方法,并添加以下行到最后:       spinner.setOnItemSelectedListener(新MyOnItemSelectedListener());

在换句话说,你需要创建一个修改第二微调的值的OnItemSelectedListener,然后将其连接到第一个微调。

I have two spinner in my system. Now I have to change the selected value of the 2nd spinner depending on the first spinner value. As soon as the user will change the 1st spinner value, the 2nd spinner value will set automatically depending upon the 1st spinner's selected value. How to implement this?

解决方案

From the Hello Spinner tutorial:

Now create a nested class that implements AdapterView.OnItemSelectedListener. This will provide a callback method that will notify your application when an item has been selected from the Spinner. Here's what this class should look like:

public class MyOnItemSelectedListener implements OnItemSelectedListener {

    public void onItemSelected(AdapterView<?> parent,
        View view, int pos, long id) {
      Toast.makeText(parent.getContext()), "The planet is " +
          parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
    }

    public void onNothingSelected(AdapterView parent) {
      // Do nothing.
    }
}

The AdapterView.OnItemSelectedListener requires the onItemSelected() and onNothingSelected() callback methods. The former is called when an item from the AdapterView is selected, in which case, a short Toast message displays the selected text; and the latter is called when a selection disappears from the AdapterView, which doesn't happen in this case, so it's ignored. Now the MyOnItemSelectedListener needs to be applied to the Spinner. Go back to the onCreate() method and add the following line to the end: spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());

In other words, you need to create an OnItemSelectedListener that modifies the value of the second spinner, and attach it to the first spinner.

这篇关于微调价值变动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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