srowley
srowley

Reputation: 837

Question on implementing Listeners in Android

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

Answers (2)

unholysampler
unholysampler

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

Gonzo
Gonzo

Reputation: 155

There is no performance difference so choose whatever makes your code easier to read

Upvotes: 0

Related Questions