我正在使用Web服务,我在onpostexecute()方法中遇到了Toast的问题。我试图根据logcat响应显示吐司.resultsRequestSOAP是我从服务器检索的字符串值。如果字符串值为1,那么我应该在toast中显示“registerd”。如果为0,则“再试一次”,如果为-1,则“字段为空”
在我的logcat中,我将响应作为字符串值。
问题是我每次都要“再试一次”祝酒消息。
问题可能是布尔(我使用的)而不是原始值,它永远不会返回null。如果(resultsRequestSOAP.booleanValue())我对此行感到困惑。它不适合我。怎么解决这个?
plz有人检查onpostexecute()中的代码并告诉我这个问题。
我想比较logcatand中的值,像这样显示吐司。 如果它的1然后“注册”, 如果是0然后“再试一次”, 如果为-1则“字段不应为空”
总是感谢帮助......!
public class Register extends Activity {
public static final Boolean resultsRequestSOAP = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
private class RegisterTask extends AsyncTask<Void, Void, Boolean> {
private final ProgressDialog dialog = new ProgressDialog(Register.this);
protected void onPreExecute() {
this.dialog.setMessage("Registering...");
this.dialog.show();
public Boolean register() {
// code for webservices********
}
return resultsRequestSOAP;
protected void onPostExecute( Boolean resultsRequestSOAP) {
if (this.dialog.isShowing()) {
this.dialog.dismiss();
}
if (resultsRequestSOAP == null) {
Toast.makeText(Register.this.getApplicationContext(), "Try Again", Toast.LENGTH_SHORT).show();
}
else if (resultsRequestSOAP.booleanValue()) {
//also show register success dialog
Toast.makeText(Register.this.getApplicationContext(), "Registerd", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(Register.this.getBaseContext(), "Field is empty", Toast.LENGTH_SHORT).show();
}
super.onPostExecute(resultsRequestSOAP);
}
答案 0 :(得分:0)
protected void onPostExecute( Boolean resultsRequestSOAP) {
if (this.dialog.isShowing()) {
this.dialog.dismiss();
}
sendResult(resultsRequestSoap);
super.onPostExecute(resultsRequestSOAP);
}
将此方法放在外层
上public void sendResult(String resultsRequestSoap){
if (resultsRequestSOAP == null) {
Toast.makeText(this, "Try Again", Toast.LENGTH_SHORT).show();
}
else if (resultsRequestSOAP.booleanValue()) {
//also show register success dialog
Toast.makeText(this, "Registerd", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(this, "Field is empty", Toast.LENGTH_SHORT).show();
}
}