做了个按键的项目,有十六个按键,0-9,a,b,c,d,*,#

开始一个个设置按键麻烦死了,后来建了一个数组直接节省了一堆代码

Button button0,button1, button2, button3;
Button button4, button5,button6, button7;
Button button8, button9,buttonx, buttony;
Button buttona, buttonb, buttonc,buttond;

Integer[] id= new Integer[]{R.id.button0,R.id.button1,R.id.button2,R.id.button3,
R.id.button4,R.id.button5,R.id.button6,R.id.button7,
R.id.button8,R.id.button9,R.id.buttona,R.id.buttonb,
R.id.buttonc,R.id.buttond,R.id.buttonx,R.id.buttony};
Button[] buttons=new Button[]{button0,button1, button2, button3,
button4, button5,button6, button7,
button8, button9,buttona, buttonb,
buttonc, buttond,buttonx, buttony};



for(int x=0;x<=15;x++){
buttons[x]=(Button)findViewById(id[x]);
}

tb_nodeStatus = nodeStatusDAO.find(PubilcDefine.KEY);
keyzhi = (int) tb_nodeStatus.getvalue1();
nodename = tb_nodeStatus.getnodename();
if(keyzhi==0xff){

}
else{
for(int i=0;i<=15;i++){
if(keyzhi==i){
if(key[i]==1){
buttons[i].setBackgroundColor(Color.RED);
key[i]=0;
keyzhi=0xff;
Tb_nodeStatus tb_nodeStatus2 = new Tb_nodeStatus(PubilcDefine.KEY, nodename, keyzhi, 0);
nodeStatusDAO.update(tb_nodeStatus2);
}else{
buttons[i].setBackgroundColor(Color.rgb(211, 211, 211));
key[i] = 1;
keyzhi = 0xff;
Tb_nodeStatus tb_nodeStatus2 = new Tb_nodeStatus(PubilcDefine.KEY, nodename, keyzhi, 0);
nodeStatusDAO.update(tb_nodeStatus2);
}
}
}

}

很轻松的写完本来应该写的一大段代码嘿嘿

更多相关文章

  1. get android kernel
  2. Android启动图3秒后自动跳转首页
  3. 【Android翻译】Support Library Setup
  4. Android(安卓)Studio问题汇总
  5. Android(安卓)4.1 Netd详细分析(五)代码分析3
  6. Android使用JSONObject和GSON方法解析JSON格式数据
  7. Android学习笔记_32_通过WebView实现JS代码与Java代码互相通信
  8. Java/Android中实现Shell命令
  9. android TextView EditTextView一些技巧使用 (视图代码布局)

随机推荐

  1. Android学习之 VideoView,SurfaceView
  2. 周末小结(五)
  3. Android的下载,编译, 运行
  4. Android掌上背包游(1)
  5. android调用web service(cxf)实例
  6. SwipeRefreshLayout——Android最棒的下
  7. Android学习笔记——关于onConfiguration
  8. Android/OPhone开发完全讲义
  9. Android(安卓)DNS之getaddrinfo()的实现
  10. Android(安卓)Studio ——Android(安卓)