草庐IT

aboutLayout

全部标签

java - 处理一个事件 : implement an interface or using inner class to handle the interface. 哪个更好

处理一个事件,有两种方式:实现回调接口(interface)举例publicclassAimplementsView.OnClickListener{publicvoidonClick(Viewv){....}@OverrideprotectedvoidonCreate(BundlesavedInstanceState){...aboutLayout=(LinearLayout)findViewById(R.id.aboutLayout);aboutLayout.setOnClickListener(this);}}创建一个实现回调接口(interface)的内部类publicclas