Android:显示基于 Logcat 响应的对话框
我正在从事网络服务工作。我想根据 logcat 响应显示对话框,该响应作为单个字符串出现。我如何解析该单个响应并向用户显示对话框。我的字符串响应有 1、-1、0 三种类型。我需要显示两个对话框。一个用于字符串类型 = 1,另一个用于字符串类型 = 0 和 -1。这是我的代码。有什么想法吗?
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();
}
}
}
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();
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论