这是我的示例代码。
public class test extends Activity {
private TextView tv;
public class Blap extends AsyncTask<String,String,Boolean>{
private test parent;
@Override
protected Boolean doInBackground(String... options) {
this.auth(options[0],options[1]);
parent.aresponse(res);
return true;
}
public Blap(test a){
this.parent = a;
}
public auth(String login, String password){
//process auth
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
//work...
}
public void buttonclick(View v){
tv = new TextView(this);
new Blap(this).execute(editText1.getText().toString(),editText2.getText().toString());
setContentView(tv);
}
public void aresponse(String rs){
tv.setText(rs);
}
}
但是当调用 aresponse 时,我遇到了一个异常:只有创建视图层次结构的原始线程才能触摸它的视图。如何正确等待异步操作完成并继续处理所需的操作?