我正在使用活动 AddDebt 来获取债务信息。我希望它然后将数据传递给我的 MainActivity 活动以进行显示。
AddDebt 如下:
public class AddDebt extends Activity implements OnClickListener {
Button Home;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_debt);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.default_menu, menu);
MenuItem gohome = menu.findItem(R.id.gohome);
Intent intent5 = new Intent(this, MainActivity.class);
gohome.setIntent(intent5);
MenuItem newDebt = menu.findItem(R.id.newDebt);
Intent intent1 = new Intent(this, AddDebt.class);
newDebt.setIntent(intent1);
MenuItem About = menu.findItem(R.id.about);
Intent intent2 = new Intent(this, About.class);
About.setIntent(intent2);
MenuItem Calcu = menu.findItem(R.id.Calcu);
Intent intent3 = new Intent(this, Calculator.class);
Calcu.setIntent(intent3);
MenuItem Manu = menu.findItem(R.id.manu);
Intent intent4 = new Intent(this, ManuPage.class);
Manu.setIntent(intent4);
return true;
}
public void ButtonOnClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.calculate:
EditText myEdit = (EditText) findViewById(R.id.editBalance);
String myEditValue = myEdit.getText().toString();
double loanAmount = Double.parseDouble(myEditValue);
EditText myEdit2 = (EditText) findViewById(R.id.editRate);
String myEditValue2 = myEdit2.getText().toString();
double interestRate = Double.parseDouble(myEditValue2);
EditText myEdit3 = (EditText) findViewById(R.id.editTerm);
String myEditValue3 = myEdit3.getText().toString();
Double loanPeriod = Double.parseDouble(myEditValue3);
double r = interestRate/1200;
double r1 = Math.pow(r+1,loanPeriod);
double editMnthlypmt = (double) ((r+(r/(r1-1))) * loanAmount);
TextView textMnthlypmt = (TextView)findViewById(R.id.textMntlypmt);
textMnthlypmt.setText("" + String.valueOf(editMnthlypmt));
break;
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
当从我的布局中选择“添加”按钮时,我希望它将数据发送到此处显示的 MainActivity:
public class MainActivity extends Activity implements OnClickListener {
Button addDebtor, Menu, About, Calc;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_table);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.default_menu, menu);
MenuItem gohome = menu.findItem(R.id.gohome);
Intent intent5 = new Intent(this, MainActivity.class);
gohome.setIntent(intent5);
MenuItem newDebt = menu.findItem(R.id.newDebt);
Intent intent1 = new Intent(this, AddDebt.class);
newDebt.setIntent(intent1);
MenuItem About = menu.findItem(R.id.about);
Intent intent2 = new Intent(this, About.class);
About.setIntent(intent2);
MenuItem Calcu = menu.findItem(R.id.Calcu);
Intent intent3 = new Intent(this, Calculator.class);
Calcu.setIntent(intent3);
MenuItem Manu = menu.findItem(R.id.manu);
Intent intent4 = new Intent(this, ManuPage.class);
Manu.setIntent(intent4);
return true;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
我不熟悉如何在任何级别上执行此操作,并且无法找到任何可行的教程来提供帮助。截至目前,我只担心传递一组数据,我可以稍后添加更多...