JJk*_*Jkk 3 string android arraylist
我想用几个月的名字填充一个arraylist.我从数据库中获得数字格式的月份.现在我想将月份数转换为月份名称并添加到数组中.我试过了,但它似乎有效.我每个月都会得到同名的名字.
int[] months = new int[count];
for(int n=0; n<count; n++) {
c.moveToNext();
months[n]= c.getInt(0);
ArrayList<String> xVals = new ArrayList<String>();
for (int i = 0; i <months.length; i++) {
Calendar cal=Calendar.getInstance();
SimpleDateFormat month_date = new SimpleDateFormat("MMMM");
cal.set(Calendar.MONTH,months[i]);
String month_name = month_date.format(cal.getTime());
xVals.add(month_name);
}
}
Run Code Online (Sandbox Code Playgroud)
Rad*_*lik 17
容易:
DateFormatSymbols symbols = new DateFormatSymbols();
String[] monthNames = symbols.getMonths();
Run Code Online (Sandbox Code Playgroud)
http://developer.android.com/reference/java/text/DateFormatSymbols.html