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.
Hibernate second-level cache ehcache.xml, the cache setting for entities can't be read to HIbernate
asynchronous file upload with java servlet
Tomcat: Session count. What is it?
Java equivalent of function mapping in Python
compiling java from the command line
How can I perform a threadsafe point-in-time snapshot of a key-value map in Java?
Find unused classes in a Java Eclipse project
Similar thing to RJS (used in Ruby on Rails) in the Java web app world?
What runs in a C heap vs a Java heap in HP-UX environment JVMs?
Creating friendly urls to dynamic resources in struts2
ant filtering - fail if property not set
How to get the system HTTP proxy configuration in Java [duplicate]
How to transform a time value into YYYY-MM-DD format in Java?
How to convert Milliseconds to “X mins, x seconds” in Java?
What is the fastest way to read a large number of small files into memory?
whats wrong with this Jar file?