圖片資源命名規則 d002_p001 ~ d002_p050,需動態構建陣列而非手寫 50 個常數。
int[] images = new int[50];
for (int i = 0; i < 50; i++) {
String resName = String.format("d002_p%03d", i + 1); // d002_p001, d002_p002...
int resId = getResources().getIdentifier(resName, "drawable", getPackageName());
if (resId != 0) {
images[i] = resId;
} else {
Log.w("RES", "Missing: " + resName);
}
}
getIdentifier(name, "drawable", packageName) 回傳 0 表示資源不存在res/drawable/ 下檔名一致(不含副檔名)getIdentifierval images = (1..50).map {
resources.getIdentifier("d002_p%03d".format(it), "drawable", packageName)
}.filter { it != 0 }.toIntArray()
assets/ 目錄,用 AssetManager.open() 讀取,無需資源 IDRecyclerView + Glide 直接用字串路徑載入