我有一个应用程序来计算屏幕混合..当按下按钮时,结果显示在同一屏幕中..我需要在新屏幕中点击按钮后显示结果...
的.java
公共类MainActivity6扩展了Activity {
double altura, largura, ratio, pixellarg, pixelalt, pixelportela, overlapperc, totallargpixel, totalpixelover, totalpixeloverfinal,numproj;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tela_blend);
Button btncalcblend = (Button) findViewById(R.id.btncalcblend);
btncalcblend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
EditText edtlargblend = (EditText) findViewById(R.id.edtlargblend);
EditText edtaltblend = (EditText) findViewById(R.id.edtaltblend);
EditText edtlargpixel = (EditText) findViewById(R.id.edtlargpixel);
EditText edtaltpixel = (EditText) findViewById(R.id.edtaltpixel);
EditText edtnumproj = (EditText) findViewById(R.id.edtnumproj);
if (edtlargblend.getText().toString().length() <= 0){
edtlargblend.setError("Digite a largura");
edtlargblend.requestFocus();
}else if (edtaltblend.getText().toString().length() <= 0){
edtaltblend.setError("Digite a altura");
edtaltblend.requestFocus();
}else if (edtlargpixel.getText().toString().length() <= 0){
edtlargpixel.setError("Digite largura pixel");
edtlargpixel.requestFocus();
}else if (edtaltpixel.getText().toString().length() <= 0){
edtaltpixel.setError("Digite altura pixel");
edtaltpixel.requestFocus();
}else if (edtnumproj.getText().toString().length() <= 0){
edtnumproj.setError("Digite número projetores");
edtnumproj.requestFocus();
}else {
largura = Double.parseDouble(edtlargblend.getText().toString());
altura = Double.parseDouble(edtaltblend.getText().toString());
pixellarg = Double.parseDouble(edtlargpixel.getText().toString());
pixelalt = Double.parseDouble(edtaltpixel.getText().toString());
numproj = Double.parseDouble(edtnumproj.getText().toString());
ratio = largura / altura;
totallargpixel = ratio * pixelalt;
totalpixelover = pixellarg * numproj;
totalpixeloverfinal = totalpixelover -totallargpixel;
pixelportela = totalpixeloverfinal / (numproj - 1);
overlapperc = (pixelportela /pixellarg) * 100;
EditText edttotalpixel = (EditText) findViewById(R.id.edttotalpixel);
edttotalpixel.setText(String.valueOf(totalpixeloverfinal));
EditText edtpixelportela = (EditText) findViewById(R.id.edtpixelportela);
edtpixelportela.setText(String.valueOf(pixelportela));
EditText edtoverlaperc = (EditText) findViewById(R.id.edtoverlaperc);
edtoverlaperc.setText(String.valueOf(overlapperc));
edtoverlaperc.setText(String.format("%.2f", overlapperc));
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edtnumproj.getWindowToken(),0);
}
}
});
Button btnvolt = (Button) findViewById(R.id.btnvoltar);
btnvolt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent dtec = new
Intent(MainActivity6.this, MainActivity.class);
MainActivity6.this.startActivity(dtec);
MainActivity6.this.finish();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
答案 0 :(得分:0)
设置活动和信息:
Intent i = new Intent(this, AActivityClass.class);
i.putExtra("Result1", result1);
i.putExtra("Result2", result2);
i.putExtra("Result3", result3);
startActivity(i);
从新活动中获取信息:
Intent intent = getIntent();
Int result1 = intent.getIntExtra("Result1", 0);
Int result2 = intent.getIntExtra("Result2", 0);
Int result3 = intent.getIntExtra("Result3", 0);