从微调器中提取值

时间:2014-07-22 01:48:45

标签: android spinner

我需要一些微调器帮助。我有三个微调器,如我上传的XML屏幕截图所示,我需要能够从公式中获取值。公式是

MSF成本= 1000 /(宽度/ 12 *长度)*厚度

宽度,长度和厚度的值可在同名的微调器中选择。 我不知道,并且还没有在网上找到一个好的指南,因为它能够获取所选的微调器值并将其放入变量以在上面的公式中使用。 enter image description here

    public class Rotary extends Activity {



    private double rollCost; // Entered Price of the Roll
    private double thickness; // selected thickness
    private double width; // selected width
    private double length; // selected length
    private double MSF; //square foot price

    EditText total; // textbox to show total value
    EditText rollPrice; //Textbox for entering price
    Spinner slength;
    Spinner swidth;
    Spinner sthick;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rotary);



        rollPrice = (EditText) findViewById(R.id.RollPrice);
        total = (EditText) findViewById(R.id.total);
        sthick = (Spinner) findViewById(R.id.Thick_spinner);
        swidth = (Spinner) findViewById(R.id.Width_spinner);
        slength = (Spinner) findViewById(R.id.length_spinner);

        //rollPrice.addTextChangedListener(rollPriceListener);
       swidth = (Spinner) findViewById(R.id.Width_spinner);
       sthick = (Spinner) findViewById(R.id.Thick_spinner);
       slength = (Spinner) findViewById(R.id.length_spinner);




        TextWatcher rollPriceListener = new TextWatcher(){

            @Override
            public void afterTextChanged(Editable arg0) {
                // TODO Auto-generated method stub

            }

            @Override
            public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                    int arg3) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onTextChanged(CharSequence arg0, int arg1, int arg2,
                    int arg3) {

                try{

                    // Change the billBeforeTip to the new input

                    rollCost = Double.parseDouble(arg0.toString());

                }

                catch(NumberFormatException e){

                    rollCost = 0.0;

                }




        };
};

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

当你想从微调器中获取值时写下面的行:

String value = YOUR_SPINNER.getSelectedItem().toString();