달력구성에서의 질문입니다..
public CalendarAdapter(Context c, GregorianCalendar monthCalendar) {
CalendarAdapter.dayString = new ArrayList<String>();
Locale.setDefault(Locale.KOREA);
month = monthCalendar;
selectedDate = (GregorianCalendar) monthCalendar.clone();
mContext = c;
month.set(GregorianCalendar.DAY_OF_MONTH, 1);
this.items = new ArrayList<String>();
df = new SimpleDateFormat("yyyy-MM-dd", Locale.KOREA);
curentDateString = df.format(selectedDate.getTime());
refreshDays();
}
public void setItems(ArrayList<String> items) {
for (int i = 0; i != items.size(); i++) {
if (items.get(i).length() == 1) {
items.set(i, "0" + items.get(i));
}
}
this.items = items;
}
public int getCount() {
return dayString.size();
}
public Object getItem(int position) {
return dayString.get(position);
}
public long getItemId(int position) {
return 0;
}
// create a new view for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (convertView == null) { // if it's not recycled, initialize some
// attributes
LayoutInflater vi = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.calendar_item, null);
}
dayView = (TextView) v.findViewById(R.id.date);
// separates daystring into parts.
String[] separatedTime = dayString.get(position).split("-");
// taking last part of date. ie; 2 from 2012-12-02
String gridvalue = separatedTime[2].replaceFirst("^0*", "");//날짜만 가져오는 부분 [2] 이부분이.
// checking whether the day is in current month or not.
if ((Integer.parseInt(gridvalue) > 1) && (position < firstDay)) {//1일 전의(전달의 마지막일들 예]29,30,31)
// setting offdays to white color.
dayView.setTextColor(Color.WHITE);
dayView.setClickable(false);
dayView.setFocusable(false);
} else if ((Integer.parseInt(gridvalue) < 7) && (position > 28)) {
dayView.setTextColor(Color.WHITE);
dayView.setClickable(false);
dayView.setFocusable(false);
} else {
// setting curent month's days in black color.
dayView.setTextColor(Color.BLACK);
}
if (dayString.get(position).equals(curentDateString)) {
setSelected(v);
previousView = v;
} else {
v.setBackgroundResource(R.drawable.list_item_background);
}
dayView.setText(gridvalue);
// create date string for comparison
String date = dayString.get(position);
if (date.length() == 1) {
date = "0" + date;
}
String monthStr = "" + (month.get(GregorianCalendar.MONTH) + 1);
if (monthStr.length() == 1) {
monthStr = "0" + monthStr;
}
//////////////////////////////////////////
SQLiteDatabase db = mDBHelper.getReadableDatabase();
cursor = db.rawQuery("SELECT * FROM today WHERE date = '" + dayString.get(position) + "'",null);
ddd = cursor.getString(1);
ImageView iw2 = (ImageView) v.findViewById(R.id.date_icon2);
if(ddd !=null){
iw2.setVisibility(View.VISIBLE);
}else{
iw2.setVisibility(View.INVISIBLE);
}
cursor.close();
mDBHelper.close();
//////////////////////
// show icon if date is not empty and it exists in the items array------일정이 있을때 아이콘(점) 표시
ImageView iw = (ImageView) v.findViewById(R.id.date_icon);
if (date.length() > 0 && items != null && items.contains(date) ) {
iw.setVisibility(View.VISIBLE);
} else {
iw.setVisibility(View.INVISIBLE);
}
return v;
}
현재 달력 각 날짜의 adapter 부분인데요,
달력 전체부분 아래에 listview로는 각 날짜에 대한 일정을 추가하여 볼 수 있는데,
현재 각 해당 부분에 날짜 아래에 이미지를 일정이 있을때는 표시, 없을때는 사라지게 하려고 하고있습니다.
근데 쿼리 부분 수행을 하기가 어려워서요.(하이라이트 부분)
지금은 보시는바와 같이 해당 날짜를 찾아서 그 부분의 제목(getString(1)) 이 null이 아니면 보이게 하도록 나름 했는데..
dayString 부분을 잘못한 것 같기도 하구요.
public class MyDBHelper extends SQLiteOpenHelper {
public MyDBHelper(Context context, String name, CursorFactory factory,
int version) {
super(context, name, factory, version);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE today(_id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT, date TEXT, time TEXT, memo TEXT);");
db.execSQL("INSERT INTO today VALUES(null, 'title', '2014/7/18', '11:00', 'memo');");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXIST today;");
onCreate(db);
}
}
이 부분이 일정에 대한 db 부분이구요.
쿼리를 adapter 안에서 어떤식으로 구현하여야 하는지 감이 잡히지 않네요..
도움 부탁드리겠습니다.