2

活动正在打开,但没有显示任何内容,我尝试将文本设置为新活动中的编辑文本,但活动根本无法打开

我是新手,所以不知道我做错了什么

        @Override 
          public void onClick(View v) {
        if
        (edtNumber1.getText().toString().equals("")|| edtNumber2.getText().toString().equals(""))
        {
        Toast msg = Toast.makeText(getBaseContext(),"Enter number please",Toast.LENGTH_LONG);
        msg.show();
        }

        else
        {
         a = Float.parseFloat(edtNumber1.getText().toString());
         b = Float.parseFloat(edtNumber2.getText().toString());
         spinner = (Spinner) findViewById(R.id.spinner1);
         selectedItem = (String) spinner.getSelectedItem();

            if (selectedItem.trim().equals("100mm")) {
                Total =  (int) (a * b * 10);
            }

            else if (selectedItem.trim().equals("215mm")) {
                Total =  (int) (a * b * 20);
            }

            else if (selectedItem.trim().equals("325mm")) {
                 Total =  (int) (a * b * 30);
            }
                Intent intent = new Intent(calculate.this,
                        BlAmounts.class);
                intent.putExtra("Result",Total);
                startActivity(intent);

            }

                   }
              });`
     }

 }

第二个活动

protected void onCreate(Bundle savedInstanceState) {
    EditText answer = (EditText) findViewById(R.id.needed); 


    super.onCreate(savedInstanceState);
    setContentView(R.layout.materials_needed);
    Intent sender = getIntent();
            int result = sender.getExtras().getInt("Result");
}
4

1 回答 1

1

首先你应该放在EditText answer = (EditText) findViewById(R.id.needed);后面setContentView(R.layout.materials_needed);

其次,您没有为answer编辑文本设置任何值。试试这个:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.materials_needed);
    EditText answer = (EditText) findViewById(R.id.needed);
    Intent sender = getIntent();
            int result = sender.getExtras().getInt("Result");
    answer.setText(result+"");
}
于 2013-04-05T21:46:37.487 回答