Supporting Multiple Screens Using Drawables Different Density

Standard

Android supports several configuration qualifiers that allow you to control how the system selects your alternative resources based on the characteristics of the current device screen. A configuration qualifier is a string that you can append to a resource directory in your Android project and specifies the configuration for which the resources inside are designed.

How to access a string using a dynamic string name in android (similar to eval in javascript)?

Standard

You have to use “android.content.res.Resources.getIdentifier”.

Strings:
strCategory1
strCategory2
strCategory3

for (int i=0; i<n; i++){
 int resID = getResources().getIdentifier("strCategory" + position, "string", getPackageName());
 String strTest = getResources().getString(resID);
}

String Arrays:
strArray1
strArray2
strArray3

for (int i=0; i<n; i++){
 int resID = getResources().getIdentifier("strArray" + position, "array", getPackageName());
 String[] strArrayTest = getResources().getStringArray(resID);
}

Drawables:
ic_category1
ic_category2
ic_category3

for (int i=0; i<n; i++){
 int resID = getResources().getIdentifier("ic_category" + position, "drawable", getPackageName());
 imgIcon.setImageDrawable(getResources().getDrawable(resID));
}