这是activityresult1
Button buttonorder;
TextView textviewcard;
private static final int REQUEST_CODE = 10;
int[] image ={R.drawable.friednoodle, R.drawable.friedrice, R.drawable.steamfish,R.drawable.tehice};
String[] item = {"Fried Noodle", "Fried Rice", "Steam Fish","Iced Tea"};
String[] description = {"Classic Chinese stir fried noodle with prawn and Pork", "Special sauce Fried Rice using indian rice", "HongKong Style Steamed Fish ","HongKong classical iced tea"};
String[] cost={"6","5","25","2"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activityresult1);
Bundle extras = getIntent().getExtras();
String strcardnumber = extras.getString("Card Number");
textviewcard = (TextView) findViewById(R.id.textviewcard);
textviewcard.setText("Welcome, " + strcardnumber + " !" + "\nPlease select the food you want ! : ");
itemList = new ArrayList<DataInfo>();
itemList.add(new DataInfo(item[0], image[0], description[0], cost[0]));
itemList.add(new DataInfo(item[1], image[1], description[1], cost[1]));
itemList.add(new DataInfo(item[2], image[2], description[2], cost[2]));
itemList.add(new DataInfo(item[3], image[3], description[3], cost[3]));
final MenuAdapter adapter = new MenuAdapter(this);
ListView listView = (ListView)findViewById(R.id.list);
LVAdapter lvAdapter = new LVAdapter(this, itemList);
//listView.setAdapter(lvAdapter);
listView.setAdapter(adapter);
for (int i = 0; i < item.length; i++) {
adapter.addData(String.valueOf(i), item[i], image[i], description[i], cost[i]);
}
buttonorder = (Button) findViewById(R.id.suborder);
buttonorder.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String[] a = adapter.getQuantity();
Toast.makeText(getApplicationContext(), "Noodle: " + a[0] + "\nRice: " + a[1] + "\nSteam fish: " + a[2] + "\nIced tea: " + a[3], Toast.LENGTH_LONG).show();
int sum = Integer.parseInt(adapter.getQuantity()[0])*Integer.parseInt(cost[0]) +
Integer.parseInt(adapter.getQuantity()[1])*Integer.parseInt(cost[1]) +
Integer.parseInt(adapter.getQuantity()[2])*Integer.parseInt(cost[2]) +
Integer.parseInt(adapter.getQuantity()[3])*Integer.parseInt(cost[3]);
Intent myIntent = new Intent(activityresult1.this, activityresult2.class);
myIntent.putExtra("sum",sum);
startActivity(myIntent);
Intent intent = new Intent(getApplicationContext(), activityresult2.class);
Bundle bundle = new Bundle();
bundle.putString("Noodle quantity", adapter.getQuantity()[0]);
bundle.putString("Rice quantity", adapter.getQuantity()[1]);
bundle.putString("Fish quantity", adapter.getQuantity()[2]);
bundle.putString("Iced tea", adapter.getQuantity()[3]);
bundle.putInt("sum", sum);
bundle.putBoolean("ANI", adapter.getItem(0).isAddInisCheck());//add noodle ingredients
bundle.putBoolean("ARI", adapter.getItem(1).isAddInisCheck()); // add rice ingredients
bundle.putBoolean("AFI", adapter.getItem(2).isAddInisCheck());// add fish ingredients
bundle.putBoolean("AIT", adapter.getItem(3).isAddInisCheck()); // add ice tea ingredients
intent.putExtras(bundle);
startActivityForResult(intent, REQUEST_CODE);
}
});
}
我如何将来自activityresult1的计算金额发送到activityresult2
static public String txtOrder ="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activityresult2);
Bundle bundle = getIntent().getExtras();
String strfnq = bundle.getString("Noodle quantity");
String strfrq = bundle.getString("Rice quantity");
String strfsq = bundle.getString("Fish quantity");
String stricq = bundle.getString("Iced tea");
Integer strsum = bundle.getInt("sum");
boolean addNingc = bundle.getBoolean("ANI");
boolean addRingc = bundle.getBoolean("ARI");
boolean addFingc = bundle.getBoolean("AFI");
boolean addTingc = bundle.getBoolean("AIT");
// boolean addmoneyc = bundle.getBoolean("AMY");
Intent mIntent = getIntent();
int sum = mIntent.getIntExtra("sum",strsum);
TextView costtext = (TextView)findViewById(R.id.costtext);
costtext.setText(getIntent().getExtras().getString("sum"));
TextView foodorders = (TextView) findViewById(R.id.foodordershow);
foodorders.setText(getIntent().getExtras().getString("Quantity"));
String addNdlThing = "";
if (addNingc) {
addNdlThing = " with addition of ingredients";
}
String addRlThing = "";
if (addRingc) {
addRlThing = " with addition of ingredients";
}
String addSlThing = "";
if ( addFingc) {
addSlThing = " with addition of ingredients";
}
String addTeac = "";
if ( addTingc ) {
addTeac = " with addition of ingredients";
}
foodorders = (TextView) findViewById(R.id.foodordershow);
if(strfnq.equals("") && strfrq.equals("") && strfsq.equals("")&& stricq.equals("")){
txtOrder = "Sorry, You've not ordered any thing , please return to previous menu to order";
}else if (!strfnq.equals("") && !strfrq.equals("") && !strfsq.equals("")&& stricq.equals("")) {
txtOrder = "Thank you , You've ordered\n" + strfnq + " fried noodle" + addNdlThing +" and\n"+ strfrq
+ " fried rice" + addRlThing +" and\n" + strfsq + " Steam fish " + addSlThing + "and\n" + stricq + " Steam fish " + addTeac;
} else {
txtOrder = "Thank you , You've ordered\n";
if(!strfnq.equals("")){
txtOrder = txtOrder + strfnq + " fried noodle" + addNdlThing;
}
if(!strfrq.equals("")){
txtOrder = txtOrder + strfrq + " fried rice" + addRlThing;
}
if(!strfsq.equals("")){
txtOrder = txtOrder + strfsq + " Steam fish" + addSlThing;
}
if(!stricq.equals("")){
txtOrder = txtOrder + stricq + " Iced Tea"+ addTeac;
}
}
foodorders.setText(txtOrder);
}
我想计算在result1中花费的钱并将其显示在结果2中 我尝试过使用他们在底部写的方法,但它不起作用,因为我不知道该填写什么。请帮助我,我真的需要这方面的帮助,我打字很多,以便使字数计数,所以我可以发布,因为我有太多的代码,他们说,请不要不喜欢这篇文章,不要这样的人,像这样和它会为双方都感到高兴,问问题并不代表我是愚蠢的
答案 0 :(得分:0)
您可以将sum
的值发送到下一个activity
,并通过Bundle
在另一个activity
中获取,如下所示。认为您将其发送到activity B
Intent i= new Intent(this,B.class);
i.putExtra("sum",sum);
startActivity(i);
您可以通过以下任一context
,activity B
,this
getActivity()
发送至getApplicationContext()
然后在activity B
中,您可以在onCreate()
方法中添加这些行,以获取传递的内容
Bundle MainActivityData= getIntent().getExtras();
int sum= MainActivityData.getString("sum");