I am working on web services. I want to show dialog box according to logcat response which come as a single string. How could i parse that single reponse and show the dialog to user. My string response is of three types which are 1, -1, 0. I need to show two dialogs. one for string type = 1 and another for string type = 0 and -1. This is my code. any idea?
package com.soap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class Register extends Activity {
/** Called when the activity is first created. */
// static Spinner operator = null;
private static final String SOAP_ACTION = "My Link";
private static final String METHOD_NAME = "My Link";
private static final String NAMESPACE = "My Link";
private static final String URL = "My Link";
private static final String TAG = "HELLO";
String resultsRequestSOAP = null;
//resultsRequestSOAP 1;
Thread t;
ProgressDialog dialog;
//Builder builder;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.forgotpasswordpage);
Button signin = (Button) findViewById(R.id.fpwdsubmit);
signin.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
showDialog(0);
t = new Thread() {
public void run() {
register();
}
};
t.start();
}
});
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case 0: {
dialog = new ProgressDialog(this);
dialog.setMessage("Please wait while connecting...");
dialog.setCancelable(true);
return dialog;
}
}
return null;
}
public void register开发者_开发知识库() {
Log.v(TAG, "Trying to Login");
EditText etxt_user = (EditText)findViewById(R.id.fpedtext);
String email_id = etxt_user.getText().toString();
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("Email", email_id);
Pattern EMAIL_ADDRESS_PATTERN =Pattern.compile(
"[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" +
"\\@" +
"[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" +
"(" +
"\\." +
"[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" +
")+");
Matcher matcher = EMAIL_ADDRESS_PATTERN.matcher(email_id);
if(matcher.matches()){
Log.v(TAG, "Your email id is valid ="+email_id);
}
else{
Log.v(TAG, "enter valid email id" );
}
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(request);
HttpTransportSE aht = new HttpTransportSE(URL);
try {
aht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
aht.call(SOAP_ACTION, soapEnvelope);
SoapObject resultsRequestSOAP = (SoapObject) soapEnvelope.bodyIn;
Log.v("TAG1", String.valueOf(resultsRequestSOAP));
dialog.dismiss();
//String resultData;
// resultData = request.getProperty(0).toString();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
精彩评论