Skip to content

Instantly share code, notes, and snippets.

@akexorcist
Created May 5, 2014 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akexorcist/8b2237931f9b1ab2be01 to your computer and use it in GitHub Desktop.
Save akexorcist/8b2237931f9b1ab2be01 to your computer and use it in GitHub Desktop.
ตัวอย่างการใช้ Listener กับหลายๆ View
Button btn1 = (Button)findViewById(R.id.btn1);
btn1.setOnClickLlistener(new OnClickListener() {
public void onClick(View v) {
// Button 1 Command
}
});
Button btn2 = (Button)findViewById(R.id.btn2);
btn2.setOnClickLlistener(new OnClickListener() {
public void onClick(View v) {
// Button 2 Command
}
});
OnClickLisetner listener new OnClickListener() {
public void onClick(View v) {
int id = v.getId;
if(id == R.id.btn1) {
// Button 1 Command
} else if(id == R.id.btn2) {
// Button 2 Command
}
}
}
Button btn1 = (Button)findViewById(R.id.btn1);
btn1.setOnClickLlistener(listener);
Button btn2 = (Button)findViewById(R.id.btn2);
btn2.setOnClickLlistener(listener);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment