package com.android.IOP;

import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import com.android.IOP.R;
import com.android.IOP.R.color;
import com.android.IOP.R.string;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class CalendarAdapter extends BaseAdapter {
 private Context mContext;
 private Calendar mBaseDate;
 private int mStartPos;
 private int mEndPos;
 private int mDaysInMonth;
 private static final int CELL_WIDTH = 40;
 private static final int CELL_HEIGH = 40;
 private static final int[] mWeekTitleIds = {
   R.string.week
     ,R.string.sun
     ,R.string.mon
     ,R.string.tue
     ,R.string.wed
     ,R.string.thr
     ,R.string.fri
     ,R.string.sat
 };
 private static final int[] mFullWeekTitleIds = {
     R.string.sunday
    ,R.string.monday
    ,R.string.tuesday
    ,R.string.wednesday
    ,R.string.thirsday
    ,R.string.friday
    ,R.string.saturday
};
 private static final int[] mWeekColorIds = {
   R.color.white
     ,R.color.red
     ,R.color.white
     ,R.color.white
     ,R.color.white
     ,R.color.white
     ,R.color.white
     ,R.color.yellow
 };

 public CalendarAdapter(Context c, Calendar cal) {
        mContext = c;
        setBaseDate(cal);
    }

    public void setBaseDate(Calendar cal) {
        mBaseDate = (Calendar)cal.clone();
        Calendar lastDayInMonth = (Calendar)cal.clone();
        lastDayInMonth.add(Calendar.MONTH, 1);
        lastDayInMonth.add(Calendar.DATE, -1);
        mDaysInMonth = lastDayInMonth.get(Calendar.DATE);
        mStartPos = 8 // 제목 행의 8개 셀
                  + mBaseDate.get(Calendar.DAY_OF_WEEK) - Calendar.SUNDAY // 일요일을 0으로 해서 요일의 순서
                  + 1 // 주 표시 셀
                  ;
        mEndPos = mStartPos
                + mDaysInMonth
                + (int)((mStartPos-9+mDaysInMonth) / 7)
                - 1
                ;     
    }
   
    @Override
 public int getCount() {
     return (mEndPos % 8 == 0) ? mEndPos : mEndPos + 1 ; // 1Week + Week Button
 }

 @Override
 public Object getItem(int arg0) {
  // TODO Auto-generated method stub
  return null;
 }

 @Override
 public long getItemId(int arg0) {
  // TODO Auto-generated method stub
  return 0;
 }

 @Override
 public View getView(int position, View oldView, ViewGroup parent) {
  // TODO Auto-generated method stub
  View v;
  if (position < 8) { // 제목 행
   if (oldView == null) {
    v = new TextView(mContext);
    ((TextView)v).setGravity(Gravity.CENTER);
    ((TextView)v).setText(mWeekTitleIds[position]);
    ((TextView)v).setTextColor(mContext.getResources().getColor(mWeekColorIds[position]));
   }
   else {
    v = oldView;
   }
  }
  else if (position % 8 == 0) { // 주차 표시 열
   if (oldView == null) {
    v = new Button(mContext);
    ((Button)v).setGravity(Gravity.CENTER);
    ((Button)v).setText(Integer.toString(position/8));
    // 현재 위치는 주차 표시 셀이므로 그 다음 위치부터가 주가 시작되는 날짜다 그래서 +3
    int nDay = getDayFromPosition(position) + 1;
    Calendar c = (Calendar)mBaseDate.clone();
    c.set(Calendar.DATE, nDay);
    v.setTag(c);
    ((Button)v).setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
               Calendar c = (Calendar)v.getTag();
               if (c == null) return;
               Calendar c1 = (Calendar)c.clone();
               c1.add(Calendar.DATE, 6);
               DateFormat df = DateFormat.getDateInstance();               
               new AlertDialog.Builder(v.getContext())
                  .setTitle(((Button)v).getText() + System.getProperty("line.separator")
                     + df.format(new Date(c.getTimeInMillis())) + " ~ " + df.format(new Date(c1.getTimeInMillis())))
                  .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int whichButton) {
                       dialog.dismiss();
                      }
                  })
                  .show();              
              }
          });     
   }
   else {
    v = oldView;
   }
  } else if (position >= mStartPos && position <= mEndPos) { // 유효한 날짜 영역
   if (oldView == null) {
   v = new TextView(mContext);
   ((TextView)v).setGravity(Gravity.CENTER);
   int nDay = getDayFromPosition(position);
   Calendar c = (Calendar)mBaseDate.clone();
   c.set(Calendar.DATE, nDay);
   v.setTag(c);
   
   ((TextView)v).setText(Integer.toString(nDay));
   ((TextView)v).setTextColor(mContext.getResources().getColor(mWeekColorIds[c.get(Calendar.DAY_OF_WEEK) - Calendar.SUNDAY + 1]));
   v.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 // Perform action on click
              Calendar c = (Calendar)v.getTag();
              if (c == null) return;
              DateFormat df = DateFormat.getDateInstance();               
              new AlertDialog.Builder(v.getContext())
                 .setTitle("일정을 입력하시오")
                 .setItems(R.array.Dialog,
                   new DialogInterface.OnClickListener(){
                     public void onClick(DialogInterface dialog, int i) {
                      choice(i);
                     
                         /* User clicked OK so do some stuff */
                     }
                 })
                 .show();              
              }
          });
   }
   else {
    v = oldView;
   }
  } else { // 빈 영역
   v = new TextView(mContext);
  }

  if (oldView == null) {
   v.setLayoutParams(new GridView.LayoutParams(CELL_WIDTH, CELL_HEIGH));
  }

  return v;
 }

 private int getDayFromPosition(int position) {
  return position - mStartPos + 1 - (int)((position-8)/8);  
 }
 
 private void choice(int i){
  Intent intent = new Intent(CalendarAdapter.this, ScheduleEdit.class);
  intent.putExtra(ScheduleEdit.dialoglist, i);
  startActivity(intent);
 }
 
 
}

빨간색 글씨인곳이 에러가 나는데 도대체 왜 에러가 나는지 모르겠어요..

일반적인 인텐트들을 다 찾아보고 수정하고 해보았는데

자꾸 저 부분에서 에러가 나요...........