0

これらは、Androidとプログラミングの私の始まりです:-)

私のAndroidアプリケーションでは、計算(文字列に変換)を次のアクティビティに伝え、そこで文字列をfloatに置き換えてifステートメントを実行します。float に基づいて、対応するメッセージが TextView に表示されます。プログラムは動作しているようですが、メッセージはランダムのようです。

最初のアクティビティ メニューのコード:

buttonNextMetric.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View v) {

           Intent intent = new Intent().setClass(Menu.this, NextMetric.class);


          intent.putExtra("ace", ace.getText().toString());

           startActivity(intent);

アクティビティ NextMetric のコード:

        textpochwala = (TextView) findViewById(R.id.textViewNextPochwala);


        try {
         float g = Float.valueOf(nextmsac.trim());
        }
        catch (NumberFormatException nfe)
        {
            System.err.println(""+ nfe.getMessage());
        }
        if (g <=10) {
            textpochwala.setText(R.string.pochwala10); 
        }
        else if (g>10 && g<=15) {
            textpochwala.setText(R.string.pochwala15);  
        }
        else if (g>15 && g<=20) {
            textpochwala.setText(R.string.pochwala20); 
        }
        else if (g>20 && g <=25) {
            textpochwala.setText(R.string.pochwala25); 
        }
        else if (g>25) {
            textpochwala.setText(R.string.pochwala30); 
        }

コードstrings.xml:

<string name="pochwala10"> A < / string>
<string name="pochwala15"> B < / string>
<string name="pochwala20"> C </ string>
<string name="pochwala25"> D </ string>
<string name="pochwala30"> E </ string>

g> 25 メッセージ E (OK)、20 < g <25 メッセージ D (OK) g <20 メッセージ A の結果のようです。メッセージ B と C は表示されません。なにが問題ですか?

エミュレーターでは、すべて正常に動作します。電話では機能しません。

4

1 に答える 1