分值纺纱 - Android电子 [英] dividing values in spinners - Android

查看:125
本文介绍了分值纺纱 - Android电子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从1微调获取值和微调2的值除以它,然后与当前量成倍增长。这是code,我有,但它给了我一个强制关闭当我尝试和转换。

I am trying to get the values from spinner 1 and divide it with the value from spinner 2 and then multiply with the current amount. This is the code i have but it gives me a force close when i try and convert.

final EditText editCurr = (EditText) findViewById(R.id.etamount);
    Button convert = (Button) findViewById(R.id.btn_convert);
     convert.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v){
             double curr = Double.valueOf(editCurr.getText().toString());


                double result2 = Double.valueOf(spinner1.toString()) / Double.valueOf(spinner2.toString());
                double result = curr * result2;
                etResult.setText(String.valueOf(result));
         }
     });

,使之更加清晰的什么,我试图做我已经表明我的数组的XML:

to make it more clearer what i'm trying to do i have shown the xml of my array:

<string-array name="currencies">
    <item>EUR, Euro</item>
    <item>GBP, British Pound</item>
    <item>USD, US Dollar</item>
    </string-array>

<string-array name="currenciesvalues">
    <item>1</item>
 <item>2</item>
    <item>3</item>
</string-array>

货币是显示在纺纱和currenciesvalues​​是分配给该字符串例如欧元具有1的值号的字符串。
在该方法中即时试图从CURR得到的量和由从除以spinner1的值与spinner2例如发生值乘以USD值3 / GBP值2

currencies are the string that show on the spinners and currenciesvalues are numbers assigned to the string e.g EUR has a value of 1. in the method im trying to get the amount from curr and multiply by the value that occurs from dividing the value of spinner1 with spinner2 e.g. USD value 3 / GBP value 2

希望这是更清楚一点。

推荐答案

您获得的值微调并将其分配给 spinner1 spinner2 某处,你有没有贴code?

Are you getting the value of the Spinner and assigning it to spinner1 and spinner2 somewhere in the code that you have not posted?

如果你不是那么这就是问题的所在。你不能仅仅通过调用获得微调的价值 spinner1.toString() spinner2.toString()

If you are not then that is where the problem is. You can't get the Spinner's value by just calling spinner1.toString() or spinner2.toString().

要得到的值微调使用...

To get the value of the spinner use...

spinner.getSelectedItem().toString(); 

所以你的情况...

So in your case...

double result2 = Double.valueOf(spinner1.getSelectedItem().toString()) / Double.valueOf(spinner2.getSelectedItem().toString());

这篇关于分值纺纱 - Android电子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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