使用Google API在Android中进行音译

时间:2013-05-16 07:25:54

标签: java android transliteration

需要帮助..!我正在开发Android Transliteration,我在代码中遇到了3个错误。

1)GoogleAPI cannot be resolved

2)Translate cannot be resolved

3)Language cannot be resolved

我已正确导入所有必需的包,并且还添加了所需的外部jar文件。但无法知道我哪里出错了..     以下是我的代码段 - >

public class MainActivity extends Activity 
{
    EditText myInputText;
    Button myTranslateButton;
    TextView myOutputText;  
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        myInputText = (EditText)findViewById(R.id.inputText);
        myTranslateButton = (Button)findViewById(R.id.translateButton);
        myOutputText = (TextView)findViewById(R.id.outputText);
            myTranslateButton.setOnClickListener(MyTranslateButtonOnClickListener);
    }

    private Button.OnClickListener MyTranslateButtonOnClickListener 
      = new Button.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            // TODO Auto-generated method stub
            String InputString;
            String OutputString = null;
            InputString = myInputText.getText().toString();

            try 
            {
                GoogleAPI.setHttpReferrer("http:\\www.google.com");
                GoogleAPI.setKey("API_KEY");
                OutputString = Translate.DEFAULT.execute(InputString,Language.ENGLISH, Language.HINDI);
            } 
            catch (Exception ex) 
            {
                ex.printStackTrace();
                OutputString = "Error";
            }
             Typeface customF = Typeface.createFromAsset(getAssets(), "akshar.ttf");
            //final TextView textV = (TextView) findViewById(...);
            myOutputText.setTypeface(customF);
            myOutputText.setText(OutputString);
        }

    };  
}

For your better understanding please have a look on following screenshots

导入的Image-1软件包 包含错误的Image-2代码 Image-3我的构建配置

Packages Imported

Code that Contains Error

My Build Configuration

请帮忙..谢谢...... !!

1 个答案:

答案 0 :(得分:1)

导入这两个:

import com.google.api.translate.Language;
import com.google.api.translate.Translate;

&安培;我认为如果您将翻译作为单独的方法使用会更好。检查this