In my Android app I have multiple activities using different array resources and I want to create one that has all of them. Is there an easy way to do this so that when I add an item to the string array it is automatically added to the "All" activity?
2
-
do you mean creating one array which can be used by all the activity ?Lucifer– Lucifer2012-06-04 03:19:26 +00:00Commented Jun 4, 2012 at 3:19
-
@Lucifer Yes, but I don't want to have to copy+paste each item into that array.GreekOphion– GreekOphion2012-06-04 03:22:58 +00:00Commented Jun 4, 2012 at 3:22
Add a comment
|
1 Answer
You need to create a generalized array in a class called ConstantCodes.java and declare your all arrays in it as follows,
public class ConstantCodes
{
public static String[][] arrayCollection = { { "A11","A22","A33" },
{ "B11","B22","B33" },
{ "C11","C22","C33" }
};
}
Calling FirstActivity.java
private String[] firstActivityArray = ConstantCodes.arrayCollection[0]; // this will return first stored array on 0th position.
Calling SecondActivity.java
private String[] secondActivityArray = ConstantCodes.arrayCollection[1]; // this will return first stored array on 1st position.