onPostExecute 出了什么问题。它显示了该方法的错误。ProgressDialog 工作正常。json 和数据库处理程序都正常工作。对 ProgressDialog 进行了相同的简化。
class ProcessBalance extends AsyncTask<String, Void, List<String>> {
private Dialog dialog;
/**
* Before starting background thread
* Show Progress Bar Dialog
* */
@Override
protected void onPreExecute() {
final Dialog dialog = new Dialog(UserhomeActivity.this);
dialog.setTitle("test");
dialog.setContentView(R.layout.dialoglayout);
dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
Button btnDismiss = (Button)dialog.getWindow().findViewById(R.id.dismiss);
// TextView balview = (TextView) dialog.findViewById(R.id.textView1);
// balview.setText("Please wait for the balance.");
//http://www.mkyong.com/android/android-custom-dialog-example/
btnDismiss.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
dialog.dismiss();
}});
dialog.show();
}
/**
* Downloading file in background thread
* */
@Override
protected List<String> doInBackground(String... args0) {
// DatabaseHandler db = new DatabaseHandler(getApplicationContext());
//HashMap<String, String> user = db.getUserDetails();
UserFunctions userFunction = new UserFunctions();
//JSONObject json = userFunction.getBalance(user.get("mobile_no"));
JSONObject json = userFunction.getBalance("1234567890");
List<String> LIST = new ArrayList<String>();
try {
if (json.getString(KEY_SUCCESS) != null) {
String res = json.getString(KEY_SUCCESS);
LIST.add(json.getString("success"));
LIST.add(json.getString("balance"));
}
} catch (NullPointerException e) {
e.printStackTrace();
}
catch (JSONException e) {
e.printStackTrace();
}
return LIST;
}
/**
* After completing background task
* Dismiss the progress dialog
* **/
protected void onPostExecute(List<String> result) {
String responseCodestr = result.get(0);
final int responseCode = Integer.parseInt(responseCodestr);
String bal = result.get(1);
TextView balview = (TextView) dialog.findViewById(R.id.textView1);
if(responseCode==1){
balview.setText("test "+bal);
} else {
balview.setText("test2");
}
}
}