我正在尝试编写一个C#程序。该功能已经实现(但在Java中)。
有没有办法像Java一样在方法中实现“DeviceController.OnDeviceControllerListener”-Interface? 我需要像Java代码示例中那样实现和自定义override-methods(onError,onRead和onInsert):
deviceController.setOnDeviceControllerListener(new DeviceController.OnDeviceControllerListener() {
@Override
public void onError(ControllerError.Error error, String message) {
}
@Override
public void onRead(MobileServiceList<Device> devices) {
if(devices == null || devices.size() == 0) {
deviceController.insert(context, device);
}
}
@Override
public void onInsert(Device device) {
}
});
我希望你理解我的问题。对我来说很难解释。
答案 0 :(得分:2)
创建自己的界面,如
interface IOnDeviceControllerListener
{
void OnError(ControllerError.Error error, String message);
void OnRead(MobileServiceList<Device> devices);
void OnInsert(Device device);
}
下一堂课:
DeviceControllerListener : IOnDeviceControllerListener
{
// implementation
}
在你的控制器定义方法(在你的情况下是setOnDeviceControllerListener)中,哪个参数是IOnDeviceControllerListener,在这种情况下设置实现DeviceControllerListener,并在IOnDeviceControllerListener的devicecontroller类调用方法的实现中