【声明】转载请注明出处,此文出自指尖飞落的博客:http://blog.csdn.net/huntersnail
——尊重作者,知识无价,交流无限!
界面No.1
List<Integer> redNums=new ArrayList<Integer>();
List<Integer> blueNums=new ArrayList<Integer>();
//设置红球适配器
PoolAdapter redAdapter=new PoolAdapter(context,33,redNums,R.drawable.id_redball);
redContainer.setAdapter(redAdapter);
//设置蓝球适配器
PoolAdapter blueAdapter=new PoolAdapter(context,16,blueNums,R.drawable.id_blueball);
blueContainer.setAdapter(blueAdapter)
界面No.2
/**
* 双色球选号容器GridView的适配器
* @author Administrator
* 2015-7-16 16:49:02
*/
public class PoolAdapter extends BaseAdapter {
private Context context;
private int endNum;
//选中后的红篮球的集合
private List<Integer> selectNums;
private int selectBgResId;
//通过构造函数传递数据
public PoolAdapter(Context context, int endNum) {
super();
this.context = context;
this.endNum = endNum;
}
//通过构造函数传递数据
public PoolAdapter(Context context, int endNum, List<Integer> selectNums) {
super();
this.context = context;
this.endNum = endNum;
this.selectNums = selectNums;
}
public PoolAdapter(Context context, int endNum, List<Integer> selectNums,
int selectBgResId) {
super();
this.context = context;
this.endNum = endNum;
this.selectNums = selectNums;
this.selectBgResId = selectBgResId;
}
@Override
public int getCount() {
return endNum;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView ball=new TextView(context);
//字符串格式化
DecimalFormat decimalFormat=new DecimalFormat("00");
//这里不能直接设置position+1,必须格式化拼接
ball.setText(decimalFormat.format(position+1));
//设置背景资源
//彩票选中的球设置成红色背景
if (selectNums.contains(position)) {
ball.setBackgroundResource(selectBgResId);
}else {
//没有选中则是默认背景
ball.setBackgroundResource(R.drawable.id_defalut_ball);
}
ball.setTextSize(16);
//文字居中
ball.setGravity(Gravity.CENTER);
return ball;
}
}
O(∩_∩)O哈哈~欢迎各种吐槽、鄙视、指教、交流......
☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆转载请注明出处☞指尖飞落的博客☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆