Import these two:
import com.google.api.translate.Language;
import com.google.api.translate.Translate;
& I think it would be better if you use the translation as a separate method.Check this out.
Frage
Need Help..! I am working on Android Transliteration and I'm getting following 3 errors in my code.
1)GoogleAPI cannot be resolved
2)Translate cannot be resolved
3)Language cannot be resolved
I have properly imported all the required packages and also have added required external jar files. But unable to know where actually I'm going wrong.. Following is my code snippet-->
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 Packages Imported Image-2 Code that Contains Error Image-3 My Build Configuration
Please help.. Thanks...!!
Lösung
Import these two:
import com.google.api.translate.Language;
import com.google.api.translate.Translate;
& I think it would be better if you use the translation as a separate method.Check this out.