程序有什么问题?当activity A跳转到activity B并从互联网请求数据更新Android UI时,UI无法更新。然后adt显示错误:
android.view.ViewRootImpl$CalledFromWrongThreadException:只有创建视图层次结构的原始线程才能接触其视图。
这是代码:
public class MyStatusesActivity extends Activity {
Button re;
TextView mystatuses;
StatusesAPI sa;
ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.my_statuses);
initView();
action();
userTimeline();
}
private void action() {
// TODO Auto-generated method stub
re.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
MyStatusesActivity.this.finish();
}
});
}
private void initView() {
// TODO Auto-generated method stub
progressDialog = ProgressDialog.show(this,null, "加载中...",true, true);
mystatuses = (TextView) findViewById(R.id.mystatuses);
re = (Button) findViewById(R.id.re);
}
public void userTimeline() {
// TODO Auto-generated method stub
sa = new StatusesAPI(SplashActivity.accessToken);
sa.userTimeline(SharePre.readUID(this), 0, 0, 20, 1, false, FEATURE.ALL, false, listener);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my_statuses, menu);
return true;
}
RequestListener listener = new RequestListener(){
@Override
public void onComplete(String arg0) {
// TODO Auto-generated method stub
Log.i("sina", arg0);
try {
JSONObject jsonObject = new JSONObject(arg0);
JSONArray jsonArray = jsonObject.getJSONArray("statuses");
JSONObject jsonOb = jsonArray.getJSONObject(0);
mystatuses.setText(jsonOb.getString("text"));
progressDialog.dismiss();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onError(WeiboException arg0) {
// TODO Auto-generated method stub
Log.i("sina", "WeiboException:"+arg0.getMessage());
}
@Override
public void onIOException(IOException arg0) {
// TODO Auto-generated method stub
Log.i("sina", "IOException:"+arg0.getMessage());
}
};