onPostExecute有什麼問題。它顯示了該方法中的錯誤。適用於ProgressDialog。 json和數據庫處理程序都正常工作。 ProgressDialog已經完成了同樣的工作。android asynctask中的自定義對話框
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");
}
}
}
什麼錯誤? –
錯誤是什麼?如果需要提供堆棧跟蹤。 – Suji
當你得到'TextView balview =(TextView)dialog.findViewById(R.id.textView1);'in'onPreExecute'然後嘗試在'onPostExecute'中設置文本時會發生什麼? (Button)dialog.findViewById(R.id.dismiss);' – Rajeev