How to reference a string-array resource with a String that is the id?
Apologies for the terrible title, but couldn't think of a better one. So I have numerous string-array's in my strings.xml file. I want to be able to reference this by passing my intent the resource id (e.g. R.array.mystringarray) as a string, and then using this string in my class to get my String. Here's what I have attempted so far to give you a better idea of what I'm trying Intent intent = new Intent(Main.this, Categories.class); intent.putExtra("category", "R.array.Categories"); startActivity(intent); Then in Categoris.class: myArrayID = (String) bundle.get("category"); myArray = getResources().getStringArray(myArrayID))); Is my method even possible? Or is there another way I've overlooked. First app and still learning the ropes EDIT - sorry, my head is fried tonight and I totally confused myself here. I have re-written the question - Converting "R.id.myID" from a String to the int value R.id.myID?
Not sure why you wanna do this, but you can pass the int ID directly: Intent intent = new Intent(Main.this, Categories.class); intent.putExtra("category", R.array.Categories); //R.array.Categories is an int value startActivity(intent); Then.. int myArrayID = bundle.getIntExtra("category", 0); myArray = getResources().getStringArray(myArrayID)));
Try this in Categoris.class String myArrayID; myArrayId=bundle.getStringArray("category");
Not much of an answer, but that is correct: see getStringArray. You will want to cast it correctly, but otherwise you got it right.
Does String Pool in Java behaves like LRU cache?
how can i deploy a bpmn file using JBPM 6.3 api and eclipse without KIE-console?
JavaFx erron in running
How to adjust accelerometer data for phones held in different positions.
Invalid Content Was Found Starting With Element
private static throughout code [closed]
Scan HBase rows by ignoring a part of the start and end row in Java
Mockito.when().thenReturn() doesn't work or returns null
Java duplicates(?) answers
Selenium code to find the word count in a paragraph
How to auto-format Java code
Convert SQL query to HQL or map result to hibernate entity
Define what value to put in a Spring cache
Spring: Accessing validation group in binding result?
Implicitly Inner Class Created in Java Enum After Compiling [duplicate]
Null HttpSessionManager with HeaderHttpSessionStrategy in Spring session