如何删除默认选择的微调器?

时间:2012-07-05 04:44:11

标签: android android-widget

它是我的salman amjad 即时通讯在我的应用程序中使用两个微调器和hav使用if else结构在每个选择......但当应用程序加载默认选择条件执行....我想删除默认选择可以任何1你PLZ帮助我在reguard ???? 第一个条件也没有在第一个...... [/ p>执行]
 convertto.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View v1,
                int index1, long arg3) {
            //from meters
            var1=Double.parseDouble(lvalue.getText().toString());
            var2=var1;
            if ((quantity[index1]=="Meter") && (s1.equalsIgnoreCase("Meter") ))
            {
            Toast.makeText(v1.getContext(), " to meter",Toast.LENGTH_SHORT).show();
            var2=var1;
            lresult.setText("" + var2);

        }
            else{
                if ((quantity[index1]=="Inches") && (s1.equalsIgnoreCase("Meter")))
                {
                Toast.makeText(v1.getContext(), " to inches",Toast.LENGTH_SHORT).show();

                var2=var1 * 39.3700787;
                lresult.setText("" + var2);

            }
                else{
                    if ((quantity[index1]=="Feet") && (s1.equalsIgnoreCase("Meter")))
                    {
                    Toast.makeText(v1.getContext(), " to Feet",Toast.LENGTH_SHORT).show();

                    var2=var1 * 3.281;
                    lresult.setText("" + var2);

                }
                    else{
                        if ((quantity[index1]=="Yards") && (s1.equalsIgnoreCase("Meter")))
                        {

                        Toast.makeText(v1.getContext(), " to Yards",Toast.LENGTH_SHORT).show();

                        var2=var1 * 1.0936133 ;
                        lresult.setText("" + var2);
                        }
                    }
                }
                //from inches
                if ((quantity[index1]=="Meter") && (s1.equalsIgnoreCase("Inches")))
                {
                Toast.makeText(v1.getContext(), " to meter",Toast.LENGTH_SHORT).show();

                var2=var1/39.3700787;
                lresult.setText("" + var2);

            }
                else{
                    if ((quantity[index1]=="Inches") && (s1.equalsIgnoreCase("Inches")))
                    {
                    Toast.makeText(v1.getContext(), " to inches",Toast.LENGTH_SHORT).show();

                    var2=var1;
                    lresult.setText("" + var2);

                }
                    else{
                        if ((quantity[index1]=="Feet") && (s1.equalsIgnoreCase("Inches")))
                        {
                        Toast.makeText(v1.getContext(), " to Feet",Toast.LENGTH_SHORT).show();

                        var2=var1/12;
                        lresult.setText("" + var2);

                    }
                        else{
                            if ((quantity[index1]=="Yards") && (s1.equalsIgnoreCase("Inches")))
                            {

                            Toast.makeText(v1.getContext(), " to Yards",Toast.LENGTH_SHORT).show();

                            var2 = var1/36;
                            lresult.setText("" + var2);
                            }
                        }
                    }
                    //from feet
                    if ((quantity[index1]=="Meter") && (s1.equalsIgnoreCase("Feet")))
                    {
                    Toast.makeText(v1.getContext(), " to meter",Toast.LENGTH_SHORT).show();

                    var2=var1/3.281;
                    lresult.setText("" + var2);

                }
                    else{
                        if ((quantity[index1]=="Inches") && (s1.equalsIgnoreCase("Feet")))
                        {
                        Toast.makeText(v1.getContext(), " to inches",Toast.LENGTH_SHORT).show();

                        var2=var1*12;
                        lresult.setText("" + var2);

                    }
                        else{
                            if ((quantity[index1]=="Feet") && (s1.equalsIgnoreCase("Feet")))
                            {
                            Toast.makeText(v1.getContext(), " to Feet",Toast.LENGTH_SHORT).show();

                            var2=var1;
                            lresult.setText("" + var2);

                        }
                            else{
                                if ((quantity[index1]=="Yards") && (s1.equalsIgnoreCase("Feet")))
                                {

                                Toast.makeText(v1.getContext(), " to Yards",Toast.LENGTH_SHORT).show();

                                var2 = var1/3;
                                lresult.setText("" + var2);
                                }
                            }
                        }
                        //from yards
                        if ((quantity[index1]=="Meter") && (s1.equalsIgnoreCase("Yards")))
                        {
                        Toast.makeText(v1.getContext(), " to meter",Toast.LENGTH_SHORT).show();

                        var2=var1/1.0936133;
                        lresult.setText("" + var2);

                    }
                        else{
                            if ((quantity[index1]=="Inches") && (s1.equalsIgnoreCase("Yards")))
                            {
                            Toast.makeText(v1.getContext(), " to inches",Toast.LENGTH_SHORT).show();

                            var2=var1*36;
                            lresult.setText("" + var2);

                        }
                            else{
                                if ((quantity[index1]=="Feet") && (s1.equalsIgnoreCase("Yards")))
                                {
                                Toast.makeText(v1.getContext(), " to Feet",Toast.LENGTH_SHORT).show();

                                var2=var1*3;
                                lresult.setText("" + var2);

                            }
                                else{
                                    if ((quantity[index1]=="Yards") && (s1.equalsIgnoreCase("Yards")))
                                    {

                                    Toast.makeText(v1.getContext(), " to Yards",Toast.LENGTH_SHORT).show();

                                    var2 = var1;
                                    lresult.setText("" + var2);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

1 个答案:

答案 0 :(得分:1)

这是因为当您第一次执行您的应用并且onItemSelected被解雇时。要摆脱这种情况,你需要自己应用一些逻辑内容,以便当Activity首次启动时,它不会在onItemSelected内部启动代码,并且在用户进行选择时起作用。 / p>

你可以做点什么,

int spinner_counter = 1, spinnner_selected = 0; // declare globally

        @Override
        public void onItemSelected(AdapterView<?> arg0, View v1,
                int index1, long arg3) {

           if(spinnner_selected < spinner_counter){
                  spinnner_selected++;
           }
           else{
                 //execute your code here
           }
        }