Android:Toast 中异步任务 onpostexecute() 的响应相同

发布于 2024-11-17 18:57:48 字数 1877 浏览 1 评论 0原文

我正在处理网络服务,并且我的 Toast 在 onpostexecute() 方法中遇到了问题。我试图根据 logcat 响应显示 toast。resultsRequestSOAP 是我从服务器检索的字符串值。如果字符串值为 1,那么我应该在 toast 中显示“registerd”。如果 0 则“重试”,如果 -1 则“字段为空”

在我的 logcat 中,我得到字符串值形式的响应。

问题是每次我收到“再试一次”的吐司消息时。

问题可能是布尔值(我正在使用)而不是从不返回 null 的原始值。我对 else if (resultsRequestSOAP.booleanValue()) 这行感到困惑。它不适合我。怎么解决这个问题?

请有人检查 onpostexecute() 中的代码并让我知道问题所在。

我想比较 logcat 中的值并像这样显示 toast。 如果为 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);
      }

I am deling with web services and I got a problem with my Toast in onpostexecute() method. I am trying to show the toast according to the logcat response.resultsRequestSOAP is a string value I am retrieving from server. If the string value is 1 then I should show "registerd" in toast. If 0 then "Try again" and If -1 then "Field is empty"

In my logcat I m getting the response as string value.

The problem is every time I am getting "Try again" toast message.

The problem might be with Boolean(which I m using) instead of primitive value which never returns null. I m confused with this line else if (resultsRequestSOAP.booleanValue()). its not working for me. how to solve this?

plz some one check the code in onpostexecute() and let me know the problem.

I want to compare the value in logcatand show the toast like this.
If its 1 then "Registered",
If its 0 then "Try again",
If its -1 then "field should not be empty"

Help is always appreciated...!

    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);
      }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丶情人眼里出诗心の 2024-11-24 18:57:48
        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();
             }


}
        protected void onPostExecute( Boolean resultsRequestSOAP) {
                 if (this.dialog.isShowing()) {
                    this.dialog.dismiss();
                 }
                 sendResult(resultsRequestSoap);
super.onPostExecute(resultsRequestSOAP);


    }

put this method on outer class

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();
             }


}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文