Is it possible to pass a bundle
to if statement
? I want to pass a value to another cases and finally total up thee two values. How can I achieve this? Now I only get the value as
and bs
, but not value amount
. I do believe it need to add a bundle
to both if statement
...
public void onActivityResult(int requestCode, int resultCode, Intent data) {
int button = data.getIntExtra("k1", 0);
long a=0;
long as=0;
long bs=0;
String result;
String result1;
if (button == 1) {
switch (requestCode) {
case 0:
result = data.getStringExtra("text");
String b = data.getStringExtra("a");
as=Long.parseLong(result);
c.setText(" " + b + "------" + "RM " + result);
Toast.makeText(getActivity(),as+"", Toast.LENGTH_LONG).show();
break;
case 1:
result = data.getStringExtra("text");
String b1 = data.getStringExtra("a");
as=Long.parseLong(result);
c.setText(" " + b1 + "------" + "RM " + result);
Toast.makeText(getActivity(),as+"", Toast.LENGTH_LONG).show();
break;
case 2:
result = data.getStringExtra("text");
String b2 = data.getStringExtra("a");
as=Long.parseLong(result);
c.setText(" " + b2 + "------" + "RM " + result);
Toast.makeText(getActivity(),as+"", Toast.LENGTH_LONG).show();
break;
case 3:
result = data.getStringExtra("text");
String b3 = data.getStringExtra("a");
as=Long.parseLong(result);
c.setText(" " + b3 + "------" + "RM " + result);
Toast.makeText(getActivity(),as+"", Toast.LENGTH_LONG).show();
break;
case 4:
result = data.getStringExtra("text");
String b4 = data.getStringExtra("a");
as=Long.parseLong(result);
c.setText(" " + b4 + "------" + "RM " + result);
Toast.makeText(getActivity(),as+"", Toast.LENGTH_LONG).show();
break;
}
}
if(button==2)
{
switch (requestCode) {
case 0:
result1 = data.getStringExtra("text");
String b = data.getStringExtra("a");
bs=Long.parseLong(result1);
d.setText(" " + b + "------" + "RM " + result1);
Toast.makeText(getActivity(),bs+"", Toast.LENGTH_LONG).show();
break;
case 1:
result1 = data.getStringExtra("text");
String b1 = data.getStringExtra("a");
bs=Long.parseLong(result1);
d.setText(" " + b1 + "------" + "RM " + result1);
Toast.makeText(getActivity(),bs+"", Toast.LENGTH_LONG).show();
break;
case 2:
result1 = data.getStringExtra("text");
String b2 = data.getStringExtra("a");
bs=Long.parseLong(result1);
d.setText(" " + b2 + "------" + "RM " + result1);
Toast.makeText(getActivity(),bs+"", Toast.LENGTH_LONG).show();
break;
case 3:
result1 = data.getStringExtra("text");
String b3 = data.getStringExtra("a");
bs=Long.parseLong(result1);
d.setText(" " + b3 + "------" + "RM " + result1);
Toast.makeText(getActivity(),bs+"", Toast.LENGTH_LONG).show();
break;
case 4:
result1 = data.getStringExtra("text");
String b4 = data.getStringExtra("a");
bs=Long.parseLong(result1);
d.setText(" " + b4 + "------" + "RM " + result1);
Toast.makeText(getActivity(),bs+"", Toast.LENGTH_LONG).show();
break;
}
}
else if(requestCode==CAMERA_REQUEST_CODE)
{
}
long amount=as+bs;
Toast.makeText(getActivity(),amount+"", Toast.LENGTH_LONG).show();
I refer How can i pass a string value, that has been created in an if statement, through a bundle inside another if statement? but the answer is quite unclear for me.
Aucun commentaire:
Enregistrer un commentaire