gpt4 book ai didi

java - 如何设置公共(public)字符串的文本

转载 作者:行者123 更新时间:2023-11-29 20:29:48 25 4
gpt4 key购买 nike

   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();
}
}
}

我正在尝试调用翻译方法并将字符串翻译返回值存储到公共(public)字符串消息中,并使用 MainActivity 类中的主 oncreate 显示。

我认为这是最简单的形式。请帮忙。 enter image description here

最佳答案

class Translate extends YandexTranslatorAPI {
public static String message;
//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);
message = translation;
System.out.println("Translation: " + translation);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

在你的 onCreate() 方法中

textElement.setText(Translate.message);

关于java - 如何设置公共(public)字符串的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32166781/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com