-1

asynctask用来显示来自 json 的数据,但 asynctask 显示加载永远不会消失,没有错误,但加载和加载此代码doInBackground功能

@Override
protected void onPreExecute() {
    progressDialog.show();
}

@Override
protected Integer doInBackground(String... arg0) {
    // check for login response
            // Creating JSON Parser instance
            JSONParser jParser = new JSONParser();
            //DatabaseHandler db = new DatabaseHandler(
                //  activity.getApplicationContext());

            // getting JSON string from URL

            JSONObject json = jParser.getJSONFromUrl(URL+id_user);

            try {
                if (json.getString(KEY_SUCCESS) != null) {
                    String res = json.getString(KEY_SUCCESS);

                    if(Integer.parseInt(res) == 1){
                        // Getting Array of Following
                        user = json.getJSONArray(KEY_USER);

                        // looping through All Following
                        for (int i = 0; i < user.length(); i++) {
                            JSONObject c = user.getJSONObject(i);

                            // Storing each json item in variable
                            nama = c.getString(KEY_NAMA);
                            instansi = c.getString(KEY_INSTANSI);
                            status = c.getString(KEY_STATUS);
                            responseCode = 1;

                        }
                        } else{
                            responseCode = 0;
                        }
                    }

                } catch (NullPointerException e) {
                    e.printStackTrace();

                }
                catch (JSONException e) {
                    e.printStackTrace();
                }

                return responseCode;
            }

@Override
protected void onPostExecute(Integer responseCode) {
    if (responseCode == 1) {
        headerNama = (TextView)activity.findViewById(R.id.headerNama);
        headerInstansi = (TextView)activity.findViewById(R.id.headerInstansi);
        buttonStatus = (Button)activity.findViewById(R.id.buttonStatus);
        headerNama.setText(nama);
        headerInstansi.setText(instansi);
        buttonStatus.setText(status);
    }else {
        progressDialog.dismiss();
        activity.showDashboardError(responseCode);

    }
}

我认为doinbackground没有问题,请帮助谢谢

4

1 回答 1

0

dismiss你应该dialog喜欢:

if (progressDialog.isShowing()) {
     progressDialog.dismiss();      
}
于 2013-05-19T14:38:42.463 回答