ArrayList with getString from Static Class [closed]

If you want to use getString instead of hard-coded text in a separate class, you need to pass Context as a parameter like this:

public static ArrayList<UserModel> getUserModelData(Context context) {
}

then use it like that:

arrayList.add(new UserModel(context.getResources().getString(R.string.droidName), context.getResources().getString(R.string.droidEmail)));

Do not forget to put your texts in strings.xml file

 <string name="droidName">Droid</string>
 <string name="droidEmail">[email protected]</string>

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top