我有一个字符串数组,其中包含工作日的名称:
private final String[] weekdays = new String[]{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
默认情况下,我已将星期一设置为一周的第一天。
现在,我为用户提供了选择是否要将星期日或星期一设置为一周的第一天的选项:
if (firstDay == 0) {
holder.txtWeekdays.setText(weekdays[position]);
}
使用相同的字符串数组如何将星期日设置为一周的第一天?
else {
holder.txtWeekdays.setText(weekdays[position]-1); //this returns an error
}
更新代码:
public class CalendarWeekAdapter extends BaseAdapter{
private final String[] weekdays = new String[]{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
Context mContext;
private LayoutInflater mInflater;
public CalendarWeekAdapter(Context c)
{
mContext=c;
mInflater = LayoutInflater.from(c);
}
public int getCount()
{
return weekdays.length;
}
public Object getItem(int position)
{
return position;
}
public long getItemId(int position)
{
return position;
}
public View getView(int position, View convertView, ViewGroup parent)
{
ViewHolder holder=null;
if(convertView==null)
{
convertView = mInflater.inflate(R.layout.calendar_week_gridcell, parent,false);
holder = new ViewHolder();
holder.txtWeekdays=(TextView)convertView.findViewById(R.id.weekdays);
if(position==0)
{
convertView.setTag(holder);
}
}
else
{
holder = (ViewHolder) convertView.getTag();
}
if (firstDay == 0) {
holder.txtWeekdays.setText(weekdays[position]);
}
else {
holder.txtWeekdays.setText(weekdays[position]);
}
return convertView;
}
}
static class ViewHolder
{
TextView txtWeekdays;
}