首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

GridView示范2(自动增长)

2012-06-27 
GridView示例2(自动增长)第一步:布局xml?第二步:定义图片的个数以及其他public int getRED_BALL_COUNT() {

GridView示例2(自动增长)

第一步:布局xml

?第二步:定义图片的个数以及其他

public int getRED_BALL_COUNT() {return RED_BALL_COUNT;}public void setRED_BALL_COUNT(int rED_BALL_COUNT) {RED_BALL_COUNT = rED_BALL_COUNT;}// 自定义适配器class BallAdapter extends BaseAdapter {// 上下文环境Context context;Drawable drawable;// 构造方法public BallAdapter(Context context, Drawable drawable) {super();this.context = context;this.drawable = drawable;}// 获得数量public int getCount() {// TODO Auto-generated method stubif (drawable == tv_gray_draw) {return getRED_BALL_COUNT();} else {return 0;}}// 获得当前选项public Object getItem(int item) {return item;}// 获得当前选项IDpublic long getItemId(int id) {return id;}public View getView(int position, View convertView, ViewGroup parent) {TextView tv_ball;if (convertView == null) {// 实例化ImageView对象tv_ball = new TextView(context);tv_ball.setLayoutParams(new GridView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));} else {tv_ball = (TextView) convertView;}tv_ball.setGravity(Gravity.CENTER);tv_ball.setTextColor(Color.BLACK);TextPaint tp = tv_ball.getPaint();tp.setFakeBoldText(true);tv_ball.setBackgroundDrawable(drawable);tv_ball.setText((position + 1) + "");return tv_ball;}}

?

?

热点排行