实现 activity 和framment通信

 1。在fragment 里写一个接口 interface
public interface onSelectListener {
public void onSelected(boolean flv);

}
2.在onAttach()方法里把接口实例化,
@Override
public void onAttach(Activity activity) {
// TODO Auto-generated method stub
super.onAttach(activity);
// 这是为了保证Activity容器实现了用以回调的接口。如果没有,它会抛出异常
try {
mCallback = (onSelectListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement onMixSettingSelectListener");
}
}


3.在activity 里实现 这个接口。

你可能感兴趣的:(Android,工具)