//曜日 Calendar c=Calendar.getInstance(); int num = c.get(Calendar.DAY_OF_WEEK); String youbi = getYoubiText(this, num); // 数値から曜日を返すメソッド1:日曜-7:土曜 public static String getYoubiText(Context context, int num) { String weekday = null; Resources res = context.getResources(); switch (num) { case 1: weekday = res.getString(R.string.youbi_1); break; case 2: weekday = res.getString(R.string.youbi_2); break; case 3: weekday = res.getString(R.string.youbi_3); break; case 4: weekday = res.getString(R.string.youbi_4); break; case 5: weekday = res.getString(R.string.youbi_5); break; case 6: weekday = res.getString(R.string.youbi_6); break; case 7: weekday = res.getString(R.string.youbi_7); break; } return weekday; }
[string.xml]
<string name="youbi_1">日</string> <string name="youbi_2">月</string> <string name="youbi_3">火</string> <string name="youbi_4">水</string> <string name="youbi_5">木</string> <string name="youbi_6">金</string> <string name="youbi_7">土</string>
コメントを残す