进度对话框完成后无更新

时间:2014-02-21 16:11:01

标签: android progressdialog ui-thread

我尝试从Google App Engine中获取数据,但希望在发生这种情况时显示进度对话框一段时间。但是当进度对话框完成时,没有任何反应。TextView字段保持空白。

这是我的代码:

...
public class EndpointsTask extends AsyncTask<Context, Integer, User> {


User user = null;
protected User doInBackground(Context... contexts) {
      Looper.prepare(); 
    final ProgressDialog ringProgressDialog = ProgressDialog.show(UserProfileActivity.this,
            "Please wait ...", "Fetching details ...", true);
             ringProgressDialog.setCancelable(true);


          new Thread(new Runnable() {

            public void run() {

              try {

                Userendpoint.Builder endpointBuilder = new Userendpoint.Builder(
                AndroidHttp.newCompatibleTransport(),
                new JacksonFactory(),
                new HttpRequestInitializer() {
                    public void initialize(HttpRequest httpRequest) { }
                });
        Userendpoint endpoint = CloudEndpointUtils.updateBuilder(
                endpointBuilder).build();

        try {
            SharedPreferences userNamePrefEditor = getApplicationContext().getSharedPreferences("usernamePref", MODE_PRIVATE);
            String id = userNamePrefEditor.getString("id", null);
           user = endpoint.getUser(id).execute();

        } catch (Exception e) {
            e.printStackTrace();
        }
     Thread.sleep(10000);

    } catch (Exception e) {
      }
    ringProgressDialog.dismiss();      
    }
    }).start();
     Looper.loop();
     return user;
}
      protected void onPostExecute(User user) {
            usernameTextView.setText("Profile Name: " + user.getUsername());
            locationTextView.setText("Location: " + user.getLocation());
            ageTextView.setText("Age: " + Integer.toString(user.getAge()));
            occupationTextView.setText("Occupation: " + user.getOccupation());
       weightTextView.setText("Weight: "+ Integer.toString(user.getWeight()));
            genderTextView.setText("Gender: " + user.getGender());
      }

    }

感谢任何帮助。

0 个答案:

没有答案