protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Translate.main(null);
TextView textElement = (TextView) findViewById(R.id.this_is_id_name);
textElement.setText(message);
//leave this line to assign a specific text
}
// Separate Class calling Translate
public final class Translate extends YandexTranslatorAPI {
public final static String message = com.mohsen.transl.Translate.translation";
//prevent instantiation
private Translate(){};
public static void main(String[] args) {
try {
setKey(ApiKeys.YANDEX_API_KEY);
String translation = Translate.execute("The quick brown fox jumps over the lazy dog.", Language.ENGLISH, Language.SPANISH);
System.out.println("Translation: " + translation);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
我正在尝试调用 translate 方法并将字符串翻译返回值存储到公共字符串消息中,并使用 MainActivity 类中的主 oncreate 显示。