如何在Spinner选择中使用任何现有的变量值?

时间:2016-01-31 14:18:54

标签: android

想在微调器选择中使用变量b的值。见代码。

  button.setOnClickListener(
  new Button.OnClickListener() {

  public void onClick(View view) {

      String name = editText.getText().toString();

      if (yes.isChecked()) {
          int age = Integer.parseInt(ageText.getText().toString());

              int l;
              l = 80 ;
              int y ;
              y = l - age ;

              c = y - 7;
              final int z;
              b = 2016 + c;

              editText3.setText((name + " you might die in the year ")+ b + "");

               } else {
                   if (no.isChecked()) {
                       int age = Integer.parseInt(ageText.getText().toString());
                            int c;

                            int l;
                            l = 80;
                            int y;
                            y = l - age;
                            c = y + 10;

                            b = 2016 + c;

                            editText3.setText(name + (" you might die in year ") + b  + "");}}} // this is button code //

现在出现了微调代码。

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

   final List<String> list = new ArrayList<String>();
                      list.add("none,i am healthy");
                      list.add("Diabetes");
                      list.add("cancer");
                      list.add("HIV/AIDS");
                      list.add("Tuberculosis");
                      list.add("Coronary Artery");
                      list.add("respiratory disease");
  ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getApplicationContext(),R.layout.support_simple_spinner_dropdown_item, list);
  String disease = spinner1.getSelectedItem().toString();
  spinner1.setAdapter(dataAdapter);

  if (disease.equals("Diabetes")) {

       int x = b-5;
       int j = 2016+ x ;
       String name = editText.getText().toString();

       editText3.setText(name + (" you might die in year ") + j  + ""); }

       else if (disease.equals("none,i am healthy")) {
       String name = editText.getText().toString();

                     int x = b + 7 ;
                     int j = 2016 + x  ;
                     editText3.setText(name + ( "you might die in year ") + j + "");


                     }

              };});


              };};

此应用程序正在执行而没有错误但它没有给我所需的输出。我如何在微调器中使用b的值(我已将其定义为全局)

0 个答案:

没有答案