java


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.

Related Links

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?

Categories

HOME
xamarin
log4j
image
asp.net-core
atom-editor
hook
cookies
mfc
iot
cvs
rdf
disassembler
networkx
python-unittest
offline
resize
spring-tool-suite
windows-phone-7
quickfix
quartz-scheduler
vaadin7
foselasticabundle
finite-automata
jsdoc
jprofiler
autoconf
jasonette
ehcache
telerik-reporting
p-value
publish
opentype
compatibility
titanium-mobile
subset-sum
mmenu
jmonkeyengine
revolution-slider
web-mining
occlusion
streamsets
hilbert-curve
tasker
trim
squib
mapzen
eclipse-scout
grid.mvc
mime
heightmap
strptime
dds
ionicons
dotnetzip
integrity
git-diff
akka-cluster
cubes
intrusion-detection
measures
py2app
paypal-express
firebaseui
moveit
prettytensor
php-internals
ios4
energy
phpcas
jfugue
r-tree
marching-cubes
content-length
jqgrid-formatter
microbenchmark
service-accounts
mmc
dundas
p2
sonarqube5.1.2
graph-api-explorer
pretty-print
typekit
dd
tablelayout
codeigniter-routing
issuu
castle
tld
aapt
jquery-layout
expected-exception
multiprocessor
inbox
soundtouch
ruby-datamapper
ora-00911
cos
smtp-auth
itmstransporter
typoscript2
ocx
pendrive
netdna-api
gnu-prolog
psi
krl
android-sdk-2.1
gamma
vc90
exchange-server-2003
mtj
boost-smart-ptr
premature-optimization
thread-local-storage
geneva-server
paul-graham
3gp
ajax-forms
caching-application-block

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App