2012-09-01 3 views
0

내 회 전자에 문제가 있습니다. 아무 것도 표시되지 않고 오류가 있습니다. 아래 코드를 확인하십시오.Android 스피너 값이 대답을 표시하지 않음

private void createSpinnerValues(){ 

    spinnerValues = new HashMap<String, Double>(); 
    spinnerValues.put("Sedentary", 1.2); 
    spinnerValues.put("Lightly Active", 1.375); 
    spinnerValues.put("Moderately Active", 1.55); 
    spinnerValues.put("Heavily Active", 1.725); 

} // end of createSpinnerValue 

private Double getAnswer(String age, String in, String ft, String weight, Double selectedItemValueFromSpinner) { 

    double answer = ((66 + (6.2377 * Double.parseDouble(weight)) + 
      (12.7084 * (Double.parseDouble(in) * 12 + Double.parseDouble(ft))) 
      - (6.8 * Double.parseDouble(age))) * selectedItemValueFromSpinner); 
    return answer; 

} // end of getAnswer method 

private Double getSelectedItemValueFromSpinnerText(String spinnerText) { 

    Double val = spinnerValues.get( spinnerText); 
    if(val==null){ 
     Log.i("DEMO", "Value is null"); } 
    return val; 

} 


     private void calculateWomen(){ 

    String f1a = etft.getText().toString(); 
    String f2a = etin.getText().toString(); 
    String f3a = etweight.getText().toString(); 
    String f4a = etage.getText().toString(); 

    if ((f1a.isEmpty() || f2a.isEmpty() || f3a.isEmpty() || f4a.isEmpty())) 
     // call for custom toast 
     viewErrorToast(); 
    else{ 
    // Metric Formula for BMR (Women) English Unit 
    //655 + (4.3379 x weight in pounds) + 
    //(4.6980 x height in inches) - (4.6756 x age in years) 
    String age, in, ft, weight; 
    Double answer; 

    age = etage.getText().toString(); 
    in = etin.getText().toString();  
    ft = etft.getText().toString(); 
    weight = etweight.getText().toString(); 

    answer = ((665 + (4.3379 * Double.parseDouble(weight)) + 
      (4.6980 * (Double.parseDouble(in)) * 12 + Double.parseDouble(ft)) 
      - (4.6756 * Double.parseDouble(age))) * 1.2); 
    BigDecimal bd = BigDecimal.valueOf(answer); 
    bd = bd.setScale(2, BigDecimal.ROUND_FLOOR); 
    etanswer.setText(bd.toString()); 


    // call for custom toast 
    viewBMRSavedToast(); 
    } 

} // end of calculateWomen method 

제발 도와주세요. 안드로이드 프로그래밍에 익숙하지 않습니다. 어떤 도움을 주시면 감사하겠습니다. 덕분에

+0

아무 것도 표시되지 않고 오류가 있습니다 ... 아직 t가 있으면 오류를 보내주세요. 그의 문제 – Araw

답변

0

나는 당신이 약간의 잘못된 방법으로 약간의 방법으로 회 전자를 사용한다고 가정한다. 어댑터 및 회 전자 설정 int pos = 0; // 클래스 변수 리스트리스트 = new ArrayList(); 회 전자 스핀 = (회 전자) findViewById (R.id.id); ArrayAdapter adapter = new ArrayAdapter (this, android.R.layout.simple_spinner_item, list); 어댑터 .setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item); spinPriceFor.setAdapter (adapter); 당신이 spinnerValues에서 두 번째 값이 필요합니다 때

채우기 목록

list.add(item); 
runOnUiThread(new Runnable() { 
      public void run() { 
       adapterRegion.notifyDataSetChanged(); 
      } 
     }); 

는 회 전자

spinSettle.setOnItemSelectedListener(new OnItemSelectedListener() { 
      @Override 
      public void onItemSelected(AdapterView<?> parent, View view, 
        int position, long id) { 
       pos=position; 
String a = list.get(pos); //do what ever you want with selected item 
      } 

      @Override 
      public void onNothingSelected(AdapterView<?> arg0) { 
      } 
     }); 

에서 요소를 선택하세요 (당신은 설정 어댑터와 skipp이 단계을 befor을 채울 수 있습니다)

spinnerValues.get(list.get(pos));