Created
May 5, 2014 20:01
-
-
Save akexorcist/8b2237931f9b1ab2be01 to your computer and use it in GitHub Desktop.
ตัวอย่างการใช้ Listener กับหลายๆ View
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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