在我的自定义中,DialogPreference
我onClick
使用View.onClickListener
执行AsyncTask
. 我的班级大致是这样的:
public class LoginDialog extends DialogPreference {
private Context mContext;
public LoginDialog(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
setDialogLayoutResource(R.layout.login_dialog);
}
@Override
protected void showDialog(Bundle bundle) {
super.showDialog(bundle);
Button pos = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE);
pos.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
...
new LoginTask(mContext, LoginDialog.this).doInBackground(user_name, user_password);
}
});
}
public class LoginTask extends AsyncTask<String, Void, Boolean> {
private LoginDialog mDialog;
private Context mContext;
public LoginTask(Context cx, LoginDialog loginDialog) {
super();
mDialog = loginDialog;
mContext = cx;
}
protected void onPreExecute() {
// this is not called, at least nothing shows up in the logs
}
protected Boolean doInBackground(String... params) {
// this is called
}
protected void onPostExecute(Boolean success) {
// this is not called, at least nothing shows up in the logs
}
}
}
为什么onPre/PostExecute
不调用这些方法?我尝试显示敬酒,记录内容,但什么也没有出现。我验证了该doInBackground
方法已被调用。