Android:Toast 中异步任务 onpostexecute() 的响应相同
我正在处理网络服务,并且我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将此方法放在外部类上
put this method on outer class