1 package com.example.nanchen.mydateviewdemo.view; android.content.Context; 4 import android.graphics.Color; 5 import android.view.Gravity; 6 import android.view.View; 7 import android.view.ViewGroup; 8 import android.view.ViewGroup.LayoutParams; 9 import android.widget.BaseAdapter; 10 import android.widget.TextView; com.example.nanchen.mydateviewdemo.R; * ÏÔʾweekµÄ²¼¾Öadapter nanchen 17 * @date 16-8-10 ÉÏÎç11:39 WeekGridAdapter extends BaseAdapter { 20 final String[] titles = new String[] { "ÈÕ", "Ò»", "¶þ", "Èý", "ËÄ", "Îå", "Áù" }; 21 private Context mContext; WeekGridAdapter(Context context) { 24 this.mContext = context; 25 } 26 27 @Override getCount() { 29 return titles.length; 30 } 31 32 @Override 33 public Object getItem(int position) { 34 return titles[position]; 35 } 36 37 @Override getItemId(int position) { 39 return position; 40 } 41 42 @Override 43 public View getView(int position, View convertView, ViewGroup parent) { 44 TextView week = new TextView(mContext); 45 android.view.ViewGroup.LayoutParams week_params = new LayoutParams( 46 android.view.ViewGroup.LayoutParams.MATCH_PARENT, 47 android.view.ViewGroup.LayoutParams.MATCH_PARENT); 48 week.setLayoutParams(week_params); 49 week.setPadding(0, 0, 0, 0); 50 week.setGravity(Gravity.CENTER); 51 week.setFocusable(false); 52 week.setBackgroundColor(Color.TRANSPARENT); (position == 6) { week.setBackgroundColor(R.color.date_weekend_text_color); 56 week.setTextColor(Color.WHITE); week.setBackgroundColor(R.color.date_weekend_text_color); 59 week.setTextColor(Color.WHITE); 60 } else { 61 week.setTextColor(Color.BLACK); 62 } 63 week.setText(getItem(position)+""); 64 return week; 65 } 66 }
11£©
MainActivity
¡¡