I am trying to respond to a result from an activity using startActivityForResult. I am getting the expected result but am unsure how to respond to the result. What I’d like to do is call a different ArrayList (which is a resource) depending on the result.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
Bundle d = data.getExtras();
String oil = d.getString("oil");
Resources res = getResources();
String[] oil_info = res.getStringArray(R.array.OIL);
...
}
}
I’d like R.array.OIL to change in response to the result. i.e. if oil = ‘BASIL’ change R.array.OIL to R.array.BASIL. I thought about making a hashmap but couldn’t figure out how to put R.array.OIL into a hashmap as you cannot put primitives in a hashmap. I am pretty new to android and java so I’m sure there is a better way to do this. Any help would be much appreciated. Thanks.
Use
getIdentifier()for your requirement as below.e.g. in array type 2 items are there as OIL and BASIL with different values.
you can access like R.array.OIL and R.array.BASIL.
In above code if string
oilis"OIL"thenidwill becomeR.array.OILandoilis"BASIL"thenidwill becomeR.array.BASIL