How to use Microsoft Translator API in Android

北战南征 提交于 2019-12-04 16:02:55
user3264088

I think you did a wrong AsyncTask. You can do it like this:

private class TransAsynTask extends AsyncTask<String, Void, String>{

    @Override
    protected String doInBackground(String... strings) {
        String output = getTranslation(strings[0]);
        return output;
    }

    @Override
    protected void onPostExecute(String s) {
        txtTranslatedText.setText("Output: " + s);
        super.onPostExecute(s);
    }
}

And in the onCreate you call:

    String textOrig;
    textOrig = txtOriginalText.getText().toString();

    new TransAsynTask().execute(textOrig);

    /*String output;
    output = getTranslation(textOrig);
    txtTranslatedText.setText("Translated Text: " + output);*/
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!