for (int i = 0; i < ROWS_TOTAL; i++) {
LinearLayout row = new LinearLayout(getContext());
row.setOrientation(LinearLayout.HORIZONTAL);
row.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, 0, 1));
content.addView(row);
// 绘制日历上的列
for (int j = 0; j < COLS_TOTAL; j++) {
RelativeLayout col = new RelativeLayout(getContext());
col.setLayoutParams(new LinearLayout.LayoutParams(0,
LayoutParams.MATCH_PARENT, 1));
col.setBackgroundResource(R.drawable.calendar_day_bg);
row.addView(col);
// 给每一个日子加上监听
col.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ViewGroup parent = (ViewGroup) v.getParent();
int row = 0, col = 0;
// 获取列坐标
for (int i = 0; i < parent.getChildCount(); i++) {
if (v.equals(parent.getChildAt(i))) {
col = i;
break;
}
}
// 获取行坐标
ViewGroup pparent = (ViewGroup) parent.getParent();
for (int i = 0; i < pparent.getChildCount(); i++) {
if (parent.equals(pparent.getChildAt(i))) {
row = i;
break;
}
}
if (onCalendarClickListener != null) {
onCalendarClickListener.onCalendarClick(row, col,
dates[row][col]);
}
}
});
}
}
具体的代码是这样的,我想通过获取被点击的部分来初始化一个calendar对象在数据库中查询这个日期的所有日程安排的。但是不知道如何获取,求帮助一下。
LinearLayout row = new LinearLayout(getContext());
row.setOrientation(LinearLayout.HORIZONTAL);
row.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, 0, 1));
content.addView(row);
// 绘制日历上的列
for (int j = 0; j < COLS_TOTAL; j++) {
RelativeLayout col = new RelativeLayout(getContext());
col.setLayoutParams(new LinearLayout.LayoutParams(0,
LayoutParams.MATCH_PARENT, 1));
col.setBackgroundResource(R.drawable.calendar_day_bg);
row.addView(col);
// 给每一个日子加上监听
col.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ViewGroup parent = (ViewGroup) v.getParent();
int row = 0, col = 0;
// 获取列坐标
for (int i = 0; i < parent.getChildCount(); i++) {
if (v.equals(parent.getChildAt(i))) {
col = i;
break;
}
}
// 获取行坐标
ViewGroup pparent = (ViewGroup) parent.getParent();
for (int i = 0; i < pparent.getChildCount(); i++) {
if (parent.equals(pparent.getChildAt(i))) {
row = i;
break;
}
}
if (onCalendarClickListener != null) {
onCalendarClickListener.onCalendarClick(row, col,
dates[row][col]);
}
}
});
}
}
具体的代码是这样的,我想通过获取被点击的部分来初始化一个calendar对象在数据库中查询这个日期的所有日程安排的。但是不知道如何获取,求帮助一下。