简体   繁体   English

使用多个android微调器同时获得结果

[英]Using multiple android spinner to get result simontaneously

This my code, I need to use both spinner result at the same time but this code return me only one spinner's selected value and for other spinner it return null. 这是我的代码,我需要同时使用两个微调器结果,但是此代码仅返回一个微调器的选定值,而对于其他微调器,它返回null。 What do I need to change in the code so that I can use both spinner simontaneously. 我需要在代码中进行哪些更改,以便可以同时使用两个微调器。

statFrom.setOnItemSelectedListener(new function());
    statTo.setOnItemSelectedListener(new function());



    }

public class function implements OnItemSelectedListener {

    String strFr, strTo;

    public void onItemSelected(AdapterView<?> parent, View arg1, int pos,
            long id) {

        Spinner spinner = (Spinner) parent;
         if(spinner.getId() == R.id.spinFrom)
         {
             strFr = spinner.getItemAtPosition(pos).toString();

         }
         if(spinner.getId() == R.id.spinTo)
         {
             strTo = spinner.getItemAtPosition(pos).toString();

         }
              Testing(strFr,strTo);
      }

Here I am getting only one spinner value and other is showing as null 在这里,我仅获得一个微调器值,而另一个显示为null

Please help me !!! 请帮我 !!!

Try replacing 尝试更换

strFr = parent.getItemAtPosition(pos).toString();

with

strFr = spinner.getItemAtPosition(pos).toString();

& Similarly for strTo 对于strTo同样如此

Ideally it is a better idea to have separate variables pointing to separate views in your code. 理想情况下,让单独的变量指向代码中的单独视图是一个更好的主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM