在Android应用程序的eclipse中,如何将数字从显示框传输到另一个活动?
Button calc = (Button)findViewById(R.id.btnCalc);
calc.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
EditText number = (EditText)findViewById(R.id.num);
EditText numberDos = (EditText)findViewById(R.id.numDos);
TextView display = (TextView)findViewById(R.id.display);
double num = Double.parseDouble(number.getText().toString());
double numDos = Double.parseDouble(numberDos.getText().toString());
num = Double.parseDouble(batdroidCalc.multNum(num));
num = num * numDos;
display.setText(num + "");
}
});
答案 0 :(得分:0)
在你的按钮中点击添加:
calc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//your code
Intent i=new Intent(Yourpagename.this,Nextpage.class);
i.putExtra("value",display.getText().toString());
startActivity(i);
}
});
然后在下一页(Nextpage.class)中,您可以获得以下值:
在第二页定义类似String value
的字符串。
value=getIntent().getExtras().getString("value");
别忘了在Android Manifest.xml中定义你的第二个活动。
答案 1 :(得分:0)
试试这个..
Button calc = (Button)findViewById(R.id.btnCalc);
calc.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
EditText number = (EditText)findViewById(R.id.num);
EditText numberDos = (EditText)findViewById(R.id.numDos);
TextView display = (TextView)findViewById(R.id.display);
double num = Double.parseDouble(number.getText().toString());
double numDos = Double.parseDouble(numberDos.getText().toString());
num = Double.parseDouble(batdroidCalc.multNum(num));
num = num * numDos;
Intent i = new Intent(getApplicationContext(),NextActivity.class);
i.putExtra("num", numos);
i.putExtra("numos", num);
startActivity(i);
}
});
<强> NextActivity.class 强>
Intent iv= getIntent();
double val = iv.getExtras().getDouble("num");
double val1 = iv.getExtras().getDouble("numos");
答案 2 :(得分:-1)
1.与args的内容 2.在单例对象中保存args 3.boardcast 等