0

这是我想翻译文本但使用http的代码我希望它直接翻译我看到了这个教程但它返回null我试图改变每个函数的返回并且我已经导入google-api-translate-java- 0.95.jar

将该 JAR 文件导入到 android buid 路径(右键单击项目->属性-> Java 构建路径->->添加外部 JARS。)请提前帮助我thanx

 main.xml:

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
     >
<TextView 
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
  </LinearLayout>

JAVA 文件

翻译器.java:

    public class Translator extends Activity {
/** Called when the activity is first created. */
    String translatedText;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    TextView tv = new TextView(this);
    Translate t = new Translate();
     public String execute(String arg0, Language arg1, Language arg2)
            throws GoogleAPIException {
        // TODO Auto-generated method stub

        return null  ;
    }

    public String[] execute(String[] arg0, Language arg1, Language arg2)
            throws GoogleAPIException {
        // TODO Auto-generated method stub
        return null;
    }

    public String[] execute(String arg0, Language arg1, Language[] arg2)
            throws GoogleAPIException {
        // TODO Auto-generated method stub
        return null;
    }

    public String[] execute(String[] arg0, Language[] arg1, Language[] arg2)
            throws GoogleAPIException {
        // TODO Auto-generated method stub
        return null;
    }};

    try {
      translatedText = t.execute("Bonjour le monde", Language.FRENCH, Language.ENGLISH);


    } catch (Exception e) {
  e.printStackTrace();
     }


    Toast.makeText(this, translatedText, Toast.LENGTH_SHORT).show();

    tv.setText(translatedText);

    setContentView(tv);
}
}
4

1 回答 1

0

我相信,谷歌翻译 API 需要 http 连接

于 2012-09-10T07:55:24.483 回答