Hashmap error,i can't load data from string
I m using hashmap for a listview.
map = new HashMap<String, Object>();
map.put("name", R.string.information);
map.put("address", R.drawable.info3);
mylist.add(map);
// ...
my problem is that i cant load string in my hashmap (R.string.information)..when i run it,i can only see some numbers instead of my text..am i doing something wrong?thanks
开发者_运维百科 <string name="information">Informations</string>
R.string.information
is just an int
. If you want the actual String
, use
map.put("name", getString(R.string.information));
string.information returns a integer instead use
getString(R.string.information);
which will give you the string that you have stored in the String.xml
Yes you are doing wrong because you have print the id the the name and address not value you should put value of the name and address tag using this one according to your requirement.
String mess = getResources().getString(R.string.name);
this.getString(R.string.name)//if you are in context
String mess = Resources.getText(R.string.name);
R.string.information gives you int value not String
You have to make change in creating hashmap Your hasmap should be
HashMap map = new HashMap<String, Integer>(); instead of `HashMap map = new HashMap<String, Object>();`
Finally code wil be
HashMap map = new HashMap<String, Integer>();
map.put("name", R.string.information);
map.put("address", R.drawable.info3);
mylist.add(map);
Thanks Deepak
精彩评论