안드로이드 개발 질문/답변
(글 수 45,052)
한화면에 버튼이 R.id.Button01 ~ R.id.Button10 까지 있다면
버튼마다
bt_button = (Button)findViewById(R.id.Button01);
bt_button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
이걸 해줘야 하나요 ?
각버튼이 눌리면 버튼에 해당하는 화면을 바꿔야 하는 버튼입니다 .
어떤 버튼이 눌렸는지 간단하게 알수있는 방법이 없을까요 ?
2010.02.17 17:42:28
implements OnClickListener
하고
View button1 = this.findViewById(R.id.Button01);
button1.setOnClickListener( this);
View button2 = this.findViewById(R.id.Button02);
button2.setOnClickListener( this);
한다음 오버라이딩된 onClick에서
Intent i;
switch (v.getId()) {
case R.id.Button01:
{
i = new Intent(this, workview.class);
i.putExtra("TITLE", "1".toString());
startActivity(i);
}
break;
case R.id.Button02:
{
i = new Intent(this, barcodelist.class);
startActivity(i);
}
break;
default:
break;
}
하니 되는군요 ㅎㅎ
{
}
요런식으로 체크하시면 됩니다.. 많으시면 switch로도 되는지 해보세요^^ㅋ