I save all the application character in R.string
.
Now I want to save the R.string character in a List.
How to declare the List?
I use
List<String> list = new ArrayList<String>();
list.add(R.string.helloworld);
And
List<integer> list = new ArrayList<integer>();
list.add(R.string.helloworld);
But I can not add it.
How to do this?
Your declaration is correct, there are problems with R.string.helloworld
. This is in fact a static int
(declaration of it is in R.java
file). Remember to import java.util
for List
and ArrayList
. If you are in Eclipse, press Ctrl + Shift + O to organize imports.
Use getString(R.string.helloworld)
:
String Resources
So your code will look like:
import java.util.ArrayList;
import java.util.List;
List<String> list = new ArrayList<String>();
list.add(getResources().getString(R.string.helloworld));
List<String> list = new ArrayList<String>();
list.add(getResources().getString(R.string.helloworld));
List<Integer> list1 = new ArrayList<Integer>();
list1.add(R.string.helloworld);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With