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

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

Categories

HOME
log4j
variables
blogger
comparison
include
fft
relay
android-4.4-kitkat
v8
midi
jplayer
serverless-framework
saxon
ab-testing
flux
beyondcompare
jprofiler
jquery-ajaxq
sox
icloud-api
java-7
opennlp
underflow
spark-jobserver
maxmind
strncpy
xacml
primitive
google-cloud-nl
fabric8
column-family
pim
force-layout
wixsharp
restlet
retina-display
neuroscience
xenforo
reportbuilder
hp-ux
google-closure
no-www
gpx
long-polling
react-scripts
python-webbrowser
blogengine.net
idisposable
svmlight
carrot
lift-json
boost-preprocessor
memory-alignment
django-scheduler
chord-diagram
google-cdn
disque
react-native-listview
apachebench
livequery
design-by-contract
associative-array
lib.web.mvc
icu4j
cakephp-3.1
notify
nsmutabledictionary
sorl-thumbnail
camanjs
fpml
rdtsc
socketexception
google-reader
has-many-through
android-radiobutton
tld
p4java
jubula
mechanize-ruby
braille
jboss-weld
ember-charts
quantlib-swig
aqtime
listings
flash-builder4.5
ril
jquery-mobile-dialog
mqx
specification-pattern
itmstransporter
venn-diagram
osql
pendrive
gnu-prolog
window-management
krl
preference
audio-capture
ti-dsp
virtual-functions
phonon
sustainable-pace
pascal-fc
w3wp
msdev
geneva-server
3gp
rtml

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App