Reputation: 837
In Android, is it better to implement Listeners in your Activity, or to individually set Listeners for each View?
For example:
public class NewActivity extends Activity implements OnClickListener {
public void onClick(View v) {
}
or
btnView.setOnClickListener(new OnClickListener({...});
Upvotes: 1
Views: 428
Reputation: 17341
There isn't much of a difference. The advantage to an anonymous class is that the implementation is not callable by anyone with a reference to your object. The downside is that you end up with a bunch of extra classes. You can choose which you feel better suits your needs.
Upvotes: 2
Reputation: 155
There is no performance difference so choose whatever makes your code easier to read
Upvotes: 0