这很简单,我像这样使用kode:
if (respondsTo(editor, "apply")) invoke(editor, "apply”);
else editor.commit();
然后我有这两种神奇的方法作为静态导入..
public static boolean respondsTo(Object object, String methodName) {
try {
object.getClass().getMethod(methodName, (Class<?>[]) null);
return Yes;
} catch (NoSuchMethodException e) {
return No;
}
}
public static Object invoke(Object object, String methodName) {
try {
return object.getClass().getMethod(methodName, (Class<?>[]) null).invoke(object);
} catch (Exception e) {
return INVOKE_FAILED;
}
}
提交在阻塞 UI 时运行,因此如果保存大数据可能会出现问题。我使用后台线程进行提交(这是有问题的......)但现在很多用户都有 2.3 所以我认为老年人应该切换......