public class Order extends Activity implements OnClickListener {
public String address = " ";
public int numButton = 0;
private final int btn = 0x8000;
private Button[] mButton = new Button[20];
private ArrayList<String> mDataList;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.order);
mDataList = new ArrayList<String>();
mButton[0] = (Button) findViewById(R.id.numButton1);
mButton[1] = (Button) findViewById(R.id.numButton2);
mButton[2] = (Button) findViewById(R.id.numButton3);
mButton[3] = (Button) findViewById(R.id.numButton4);
mButton[4] = (Button) findViewById(R.id.numButton5);
mButton[5] = (Button) findViewById(R.id.numButton6);
mButton[6] = (Button) findViewById(R.id.numButton7);
mButton[7] = (Button) findViewById(R.id.numButton8);
mButton[8] = (Button) findViewById(R.id.numButton9);
mButton[9] = (Button) findViewById(R.id.numButton10);
mButton[10] = (Button) findViewById(R.id.numButton11);
mButton[11] = (Button) findViewById(R.id.numButton12);
mButton[12] = (Button) findViewById(R.id.numButton13);
mButton[13] = (Button) findViewById(R.id.numButton14);
mButton[14] = (Button) findViewById(R.id.numButton15);
mButton[15] = (Button) findViewById(R.id.numButton16);
mButton[16] = (Button) findViewById(R.id.numButton17);
mButton[17] = (Button) findViewById(R.id.numButton18);
mButton[18] = (Button) findViewById(R.id.numButton19);
mButton[19] = (Button) findViewById(R.id.numButton20);
// 버튼들에 대한 클릭리스너 등록 및 각 버튼이 클릭되었을 때 출력될 메시지 생성(리스트)
for(int i = 0 ; i < 20 ; i++)
{ // 버튼의 포지션(배열에서의 index)를 태그로 저장
mButton[i].setTag(i);
// 클릭 리스너 등록
mButton[i].setOnClickListener(this);
}
public void onClick(View v) {
Button newButton = (Button) v;
for(Button tempButton : mButton);
{
if(tempButton == newButton)
{
newButton.setBackgroundResource(R.drawable.btn2);
newButton.setSelected(true);
}
}
}
위의 소스에서 20개의 버튼을 배열로 만든 후
클릭된 버튼에 한해 이벤트 처리를 해주고 싶은데
밑의 tempButton 부분에서 에러가 나네요...
혹시 이 방법 외에 onClick 에서
클릭된 버튼을 찾을 수 있는 방법이 있을까요?