Button 简单写,优化代码

gongneng = new Button[7];
gongneng[0] = (Button) findViewById(R.id.a_bt);
gongneng[1] = (Button) findViewById(R.id.b_bt);
gongneng[2] = (Button) findViewById(R.id.c_bt);
gongneng[3] = (Button) findViewById(R.id.d_bt);
gongneng[4] = (Button) findViewById(R.id.e_bt); //兑换按钮当前隐藏了
//新加如 5 公告 6 好友
gongneng[5] = (Button) findViewById(R.id.f_bt);
gongneng[6] = (Button) findViewById(R.id.g_bt);

for (int i = 0; i < 7; i++) {
gongneng[i].setOnClickListener(this);   //用循环把按钮的监听器全部初始化
}


//实现按钮1 
if (v == gongneng[0]) {

}

  

原文地址:https://www.cnblogs.com/firecode/p/3084977.html