如何设置 Public 字符串的文本

How to setText of a Public String

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

我正在尝试调用翻译方法并将字符串翻译 return 值存储到 public 字符串消息中,并使用 MainActivity Class 中的主 oncreate 显示。

我认为这是最简单的形式。请帮忙。

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