아래는 사용하는 코드입니다
일단 CalenderView.java는 잘 동작하는거 확인했으니 패스구요
먼저 Linearlayout month을 정의하고 month에 각각 xml에 있는 month들을 연결했습니다 물론 Linearlayout이구요
그다음 해당 month.addView(calender)해서 calender를 집어넣고 싶은데.... 디버깅 해보면 자꾸 month에 null값이 들어간다고 나옵니다 실제 calender값은 null이 아닌데도 말이죠....
이거 어떻게야 해결할 수 있을까요? 답변 부탁드립니다....
public class HaksaActivity extends Activity {
List<Map<String, Object>> yearSchedule = new ArrayList<Map<String, Object>>() ;
LinearLayout month1,month2,month3,month4,month5,month6,month7,month8,month9,month10,month11,month12;
private Context mcontext;
private GregorianCalendar today = new GregorianCalendar();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mcontext = this;
setContentView(R.layout.layout_haksa_schedule);
initSchedule();
init();
ViewPager pager = (ViewPager) findViewById(R.id.Haksa_pager);
pager.setAdapter(new monthpageAdapter(this));
Button mapBackBtn = (Button) findViewById(R.id.btn_back);
mapBackBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
}
public void init(){
month1 = (LinearLayout) findViewById(R.id.month1);
month2 = (LinearLayout) findViewById(R.id.month2);
month3 = (LinearLayout) findViewById(R.id.month3);
month4 = (LinearLayout) findViewById(R.id.month4);
month5 = (LinearLayout) findViewById(R.id.month5);
.....
month12 = (LinearLayout) findViewById(R.id.month12);
monthMethod(month1,1);
monthMethod(month2,2);
monthMethod(month3,3);
monthMethod(month4,4);
monthMethod(month5,5);
monthMethod(month6,6);
.....
monthMethod(month12,12);
}
private List<Map<String, Object>> getMonthlyScheduleList(int month) {
List<Map<String, Object>> monthlySchedule = new ArrayList<Map<String, Object>>();
for (Map<String, Object> map : yearSchedule) {
String mMonth = map.get("first_date").toString().substring(5, 7);
String preMonth = map.get("last_date").toString().substring(5, 7);
if (Integer.parseInt(mMonth) == month + 1
|| Integer.parseInt(preMonth) == month + 1)
monthlySchedule.add(map);
}
return monthlySchedule;
}
class Holder{
public int m;
}
private void initSchedule() {
new SmartCampusAsyncTask().doRunExecute(mcontext, new TaskFunction() {
JSONObject object;
@Override
public void doRun() {
try {
object = Face3Utils.getUrlToJsonObject(
SmartCampusVariable
.getServerHttpUrl("/commondata/getAllAcademicSchedule.do"),
null);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void doFinish() {
try {
if (object != null)
yearSchedule = DwAndroidUtils.jsonArrayToList(
object.getJSONArray("list"), yearSchedule);
else
Toast.makeText(mcontext, "서버로부터 정보를 받아오지 못하였습니다.",
Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}, "학사일정을 불러오는 중입니다.");
}
public void monthMethod(final View v,int k) {
CalendarView calendar;
calendar = new CalendarView(mcontext, k,
today.get(GregorianCalendar.YEAR), getMonthlyScheduleList(k));
((LinearLayout) v).addView(calendar);
}
}