12-18 21:09:15.104: ERROR/AndroidRuntime(4368):
android.view.ViewRoot$CalledFromWrongThreadException: Only the original
thread that created a view hierarchy can touch its views.
i am using google translate api to practice.when i write a new thread,and
use setText() in this thread, error turn out.where i can set text to
TextView. my code is as follow:
public class TranslateApp extends Actitvity{
EditText mEditText;
TextView mTextView;
Button btn;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mEditText = (EditText) findViewById(R.id.question);
mTextView = (TextView) findViewById(R.id.answer);
}
@Override
public void onClick(View arg0) {
Log.i(TAG, "translate begins...");
new Thread(){
public void run(){
try {
String result = Translator.translate(mEditText.getText());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.i(TAG, "translate ends.");
mTextView.setText(result);
}
}.start();
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en