在 Eclipse 为您创建的来自 Google 的示例 master-detail-flow 代码中,片段中有以下内容:
private Callbacks mCallbacks = sDummyCallbacks;
public interface Callbacks {
public void onItemSelected(String id);
}
private static Callbacks sDummyCallbacks = new Callbacks() {
@Override
public void onItemSelected(String id) {
}
};
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
mCallbacks = (Callbacks) activity;
}
@Override
public void onDetach() {
super.onDetach();
// Reset the active callbacks interface to the dummy implementation.
mCallbacks = sDummyCallbacks;
}
我了解如何使用回调接口从片段与包含 Activity 的片段进行通信,但是这个虚拟回调有什么用?