活动正在打开,但没有显示任何内容,我尝试将文本设置为新活动中的编辑文本,但随后活动根本无法打开
我是新手,所以不知道我做错了什么
@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");
}
答案 0 :(得分: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+"");
}