I have created an app with 5 activities where the user will input numbers into 4 edit text fields on each activity and move between them in a sequence with a "Next" Button.
I want to be able to save/gather all of the user inputs across the activities and calculate a maths formula to be displayed in text view on another activity .
What can be recommended to do this?
Thanks in advance!
答案 0 :(得分:0)
使用putExtra将数字传递给下一个活动
单击下一步按钮的活动A
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getActivity(), BActivity.class);
i.putExtra("A1", String.valueOf(firstnumber));
i.putExtra("A2", String.valueOf(secondnumber));
i.putExtra("A3", String.valueOf(thirdnumber));
i.putExtra("A4", String.valueOf(fourthnumber));
startActivity(i);
}
});
onCreate中的活动B
Bundle extras = getIntent().getExtras();
String firstnumber = extras.getString("A1");
String secondnumber = extras.getString("A2");
String thirdnumber = extras.getString("A3");
String fourthnumber = extras.getString("A4");
int A = Integer.valueOf(firstnumber);
int B = Integer.valueOf(secondnumber);
int C = Integer.valueOf(thirdnumber);
int D = Integer.valueOf(fourthnumber);
然后继续将数字发送到下一个活动。