0

こんにちは、私はアンドロイドの初心者です..メニューウィンドウから Android の登録ウィンドウと呼ばれる別のアクティビティに BMI の計算を表示するにはどうすればよいかを尋ねたいだけです..このコードを実行すると、登録ウィンドウに結果が表示されないためです. 。 ありがとうございました

*登録ウィンドウ *


  public void onClick(View v)
    {   
        Intent intent = new Intent(Register.this, Menu.class);
            intent.putExtra("response","counter");
            startActivity(intent);   

        int weight = 0, height = 0, age = 0, answer = 0;
        String test1, test2, test3;
        test1 = getString(R.id.tvWeight);
        test2 = getString(R.id.tvAge);
        test3 = getString(R.id.tvHeight);

        try {
            if (test1 != "" && test2 != "" && test3 != "") {
                Eweight = (EditText) findViewById(R.id.tvWeight);
                weight = Integer.parseInt(Eweight.getText().toString().trim());
                Eage = (EditText) findViewById(R.id.tvAge);
                age = Integer.parseInt(Eage.getText().toString().trim());
                Eheight = (EditText) findViewById(R.id.tvHeight);
                height = Integer.parseInt(Eheight.getText().toString().trim());

                if(gender.contains("Male"))
                    answer = (int) Math.round(1.2 * (66 + (13.7 * weight) + (5 * height) - (6.8 * age)));

                if(gender.contains("Female"))
                    answer = (int) Math.round(1.2*(655 + (9.6 * weight) + (1.8 * height) - (4.7 * age)));

                response = answer + " kcal/day";
                counter.setText(response);


            }
        } catch (Exception e) {
            System.out.println(e);
        }

    }     

メニューウィンドウ

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                Intent intent = getIntent();
                intent.getStringExtra("response");

                String answer = intent.getStringExtra(response);


            }
        });
4

1 に答える 1

0

十分な詳細を提供していないため、詳細に回答することは困難genderです。

Activityレイアウト (表示されているもの) を変更するためだけに新しいものは必要ありません。メソッド内でやりたいことonClick()(レイアウト変更含む)をするだけ。

Activityとにかく新しいものでやりたい場合は、を使用する必要がありますstartActivityForResult()Bundle(3 番目のパラメーター) を使用して、必要なものを new に渡すことができますActivity。この新しい Activityが終了するonActivityResult()と、ここで信じているようにコードの次の文ではなく、呼び出し元が呼び出されることに注意してください。

    Intent intent = new Intent(Register.this, Menu.class);
    intent.putExtra("response","counter");
    startActivity(intent);   

    int weight = 0, height = 0, age = 0, answer = 0;
    String test1, test2, test3;
    test1 = getString(R.id.tvWeight);
    test2 = getString(R.id.tvAge);
    test3 = getString(R.id.tvHeight);

PS: Java では、クラス/インターフェース名のみが大文字で始まります。クラス フィールドは小文字で始まります。

于 2013-01-22T12:17:22.933 に答える