我正在爲Android創建Phonegap插件。當我將findViewById
方法添加到this.ctx.runOnUiThread(new Runnable()
時,我收到標題中所述的錯誤。FindViewById(int)的方法未定義爲新類型Runnable(){}
這裏是我的代碼:
package com.company.msgbox;
import java.io.File;
import org.crossplatform.phonegap.trial.alternativeTo.R;
import org.json.JSONArray;
import org.json.JSONException;
import android.app.AlertDialog;
import android.graphics.Bitmap;
import android.view.View;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import com.phonegap.api.PluginResult.Status;
public class msgbox extends Plugin {
private static final String SHOW = "show";
private static final int MSG_INDEX = 0;
private String msg;
@Override
public PluginResult execute(String arg0, final JSONArray arg1, String arg2) {
if (arg0.equals(SHOW)) {
this.ctx.runOnUiThread(new Runnable() {
public void run() {
// try/catch generated by editor
try {
msg = arg1.getString(MSG_INDEX);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
AlertDialog alertDialog = new AlertDialog.Builder(ctx).create();
alertDialog.setTitle("Title");
alertDialog.setMessage(msg);
alertDialog.show();
View content = findViewById(R.id.layoutroot);
Bitmap bitmap = content.getDrawingCache();
File file = new File("/sdcard/test.png");
}
});
}
return new PluginResult(Status.OK);
}
}
請工作在你的縮進。現在代碼不可讀。 – Gray
我編輯了縮進,等待驗證。這確實是不可讀 – Guillaume
感謝Guillaume :) – jcrowson