GridView日历
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
1.GridView的布局文件main.xml
xmlns:android="/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> android:gravity="center" android:id="@+id/gridview" android:background="#A9A9A9" android:padding="1.0dip" android:scrollbars="none" android:fadingEdge="none" android:layout_width="316.0dip" android:layout_height="wrap_content" android:horizontalSpacing="1.0dip" android:verticalSpacing="1.0dip" android:numColumns="7" android:layout_centerHorizontal="true" />
2.GridView的显示内容的textview.xml
android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#FFFFFF"> android:gravity="center" android:layout_width="67.5px" android:layout_height="77px" android:textSize="36px" android:id="@+id/tvtext" />
3.activity
public class CalenderActivity extends Activity {
Calendar cal = Calendar.getInstance();
int currentYear = cal.get(Calendar.YEAR);
int currentMonth = cal.get(Calendar.MONTH);
int currentDay=cal.get(Calendar.DAY_OF_MONTH);
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(yout.main);
GridView gridview = (GridView) findViewById(R.id.gridview);
// 添加元素给GridView
GridAdapter gadapt = new GridAdapter(this, currentYear, currentMonth); gridview.setAdapter(gadapt);
}
}
4.最重要的adapter,GridAdapter
public class GridAdapter extends BaseAdapter {
int week;
int monthDays;
Calendar cal = Calendar.getInstance();
// 定义Context
private Context mContext;
// 数组
private String[] number = new String[42];
public GridAdapter(Context c, int currentYear, int currentMonth) { mContext = c;
getweek(currentYear, currentMonth);
}
// 获取个数
public int getCount() {
return number.length;
}
// 获取位置
public Object getI tem(int position) {
return position;
}
// 获取ID
public long getItemId(int position) {
return position;
}
Object tvPos;
public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) {// 第一屏
convertView = LayoutInflater.from(mContext).inflate(
yout.textview, null);
}
TextView textview = (TextView) convertView.findViewById(text); String strpos = number[position];
textview.setText(strpos);