0

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 ? Commented Jun 4, 2012 at 3:19
  • @Lucifer Yes, but I don't want to have to copy+paste each item into that array. Commented Jun 4, 2012 at 3:22

1 Answer 1

1

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.