1.匿名内部类实现
button.setOnClickListener(new OnclickListener(){ @Override public void onClick(View arg0){ // do whatever you want here } };
2.独立类实现
OnclickListener listener = new OnClickListener(){ @Override public void onClick(View arg0){ // do whatever you want here } }; button.setOnClickListener(listener);
3.接口实现
public class MainActivity extends Activity implements OnClickListener{ // the class itself // ...... button.setOnClickListener(this); }
网友评论