我在互联网上找到了这个代码,它起到了消息框的作用。代码工作得非常好。但是,它显示存储在文件message.db中的所有消息。
我的问题是,如何才能显示最近发布的20条消息?对不起,我很抱歉。我对编程不了解。我感谢任何帮助...
以下是代码片段:
function limitToFilter(){
return function(array, limit) {
if (!(array instanceof Array)) return array;
limit = int(limit);
var out = [],
i, n;
// check that array is iterable
if (!array || !(array instanceof Array))
return out;
// if abs(limit) exceeds maximum length, trim it
if (limit > array.length)
limit = array.length;
else if (limit < -array.length)
limit = -array.length;
if (limit > 0) {
i = 0;
n = limit;
} else {
i = array.length + limit;
n = array.length;
}
for (; i<n; i++) {
out.push(array[i]);
}
return out;
我发现这个函数限制了结果:
08-24 06:24:11.669 3275-3275/com.sano.tamer.prompuserinputdialog W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
08-24 06:24:11.669 3275-3275/com.sano.tamer.prompuserinputdialog W/IInputConnectionWrapper: endBatchEdit on inactive InputConnection
08-24 06:24:19.019 3275-3275/com.sano.tamer.prompuserinputdialog D/AndroidRuntime: Shutting down VM
08-24 06:24:19.019 3275-3275/com.sano.tamer.prompuserinputdialog W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x5c8d4160)
08-24 06:24:19.039 3275-3275/com.sano.tamer.prompuserinputdialog E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sano.tamer.prompuserinputdialog, PID: 3275
java.lang.NullPointerException
at com.sano.tamer.prompuserinputdialog.MainActivity$1$2.onClick(MainActivity.java:48)
at android.support.v7.app.AlertController$ButtonHandler.handleMessage(AlertController.java:157)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5252)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
at dalvik.system.NativeStart.main(Native Method)
} }
现在,我只需要帮助将它们组合在一起以使脚本工作。我希望有人能帮帮忙。我真的不知道......谢谢。