android如何新建登录界面,在android中创建一个登录页面

尝试这个

public class Login extends Activity {

/** Called when the activity is first created. */

private static final String SOAP_ACTION = "http://tempuri.org/LoginUser";

private static final String METHOD_NAME = "LoginUser";

private static final String NAMESPACE = "http://tempuri.org/";

private static final String URL = "http://";

private static final String TAG = "HELLO";

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Button signin = (Button) findViewById(R.id.regsubmitbtn);

signin.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

new StartLoginAsyncTask(yourclass.this).execute();

}

});

}

private class LoginTask extends AsyncTask {

private final ProgressDialog dialog = new ProgressDialog(YourClass.this);

protected void onPreExecute() {

this.dialog.setMessage("Logging in...");

this.dialog.show();

}

protected Boolean doInBackground(final Void unused) {

return Main.this.login(); //don't interact with the ui!

}

protected void onPostExecute(final Boolean result) {

if (this.dialog.isShowing()) {

this.dialog.dismiss();

}

if (result.booleanValue()) {

//also show register success dialog

}

}

}

private String doLogin() {

EditText etxt_user = (EditText)findViewById(R.id.emaileditlog);

String email_id = etxt_user.getText().toString();

EditText etxt_password = (EditText)findViewById(R.id.pwdeditlog);

String password = etxt_password.getText().toString();

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

request.addProperty("email", email);

request.addProperty("password", password);

SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

soapEnvelope.dotNet = true;

soapEnvelope.setOutputSoapObject(request);

HttpTransportSE aht = new HttpTransportSE(URL);

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

// System.out.println("Your email id is valid ="+email);

}

else{

// System.out.println("enter valid email id");

Log.v(TAG, "enter valid email id" );

}

if (password != null)

{

if(email_id.equalsIgnoreCase("")||password.equalsIgnoreCase(""))

{

System.out.println("Fields should not be EMPTY");

}

}

SoapObject request = new SoapObject(NAMESPACE_LOGIN, METHOD_NAME_LOGIN);

request.addProperty("email", email_id);

request.addProperty("pwd", password);

SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

soapEnvelope.dotNet = true;

soapEnvelope.setOutputSoapObject(request);

HttpTransportSE aht = new HttpTransportSE(URL_LOGIN);

try {

aht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

aht.call(SOAP_ACTION_LOGIN, soapEnvelope);

SoapObject resultsRequestSOAP = (SoapObject) soapEnvelope.bodyIn;

Log.v("TAG", String.valueOf(resultsRequestSOAP));

Object response=(Object)soapEnvelope.getResponse();

temp=response.toString();

} catch (Exception e) {

e.printStackTrace();

}

return(temp);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值