java - Using Strings from resources in List. -
i'm new android , i'm having problem using string variables resources in code. tried couple of solutions found on internet , android api guides, didn't work in specific case, me not using them correctly.
to more specific, have master/detail flow activity , use resource strings item names multilanguage purposes, have problem recovering actual strings. error is:
cannot resolve method 'getstring()'
here code based on android studio dummy file
public class categories { public static list<catname> items = new arraylist<catname>(); static { string temp = getstring(r.string.cat_n1); additem(new catname("1", temp); } private static void additem(catname item) { items.add(item); } public static class catname { public string id; public string name; public fieldcat(string id, string name) { this.id = id; this.name = name; } @override public string tostring() { return name; } }}
you need specify resource. try this,
getresources().getstring(r.string.cat_n1);
getstring(int resid)
: return localized string application's package's default string table.
getresources().getstring(int id)
: returns string value associated particular resource id. stripped of styled text information.
Comments
Post a Comment