【聲明】轉載請註明出處,此文出自指尖飛落的博客: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哈哈~歡迎各種吐槽、鄙視、指教、交流......
☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆轉載請註明出處☞指尖飛落的博客☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆