问题描述
|
我有一个登录页面,当我输入正确的用户名和密码时,它可以正常工作,但是对于登录失败,它无法正常工作。
在android中,我不知道是否有人可以提供代码
这是我的代码:
package com.android;
import java.io.IOException;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import org.json.JSONException;
import org.json.JSONObject;
import org.ksoap2.soapEnvelope;
import org.ksoap2.soapFault;
import org.ksoap2.serialization.soapObject;
import org.ksoap2.serialization.soapPrimitive;
import org.ksoap2.serialization.soapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.xmlpull.v1.XmlPullParserException;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.*;
public class Login extends Activity {
private static final String NAMESPACE = \"http://tempuri.org/\";
private static final String URL =\"http:.asmx?op=LoginRequest\";
private static final String SOAP_ACTION = \"http://tempuri.org/Login\";
//private String login=\"\";
private static final String METHOD_NAME = \"Login\";
ImageButton login_button,sign_button;
TextView m,p,f,email,password,forgot_password;
EditText emailid,epassword;
AlertDialog authProgressDialog;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestwindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.login);
email=(TextView)findViewById(R.id.email);
password=(TextView)findViewById(R.id.password);
forgot_password=(TextView)findViewById(R.id.forgot);
Context context = email.getContext();
Typeface font=Typeface.createFromAsset(context.getAssets(),\"arial.ttf\");
email.setTypeface(font);
Context con = password.getContext();
Typeface face=Typeface.createFromAsset(con.getAssets(),\"arial.ttf\");
password.setTypeface(face);
Context con1 = forgot_password.getContext();
Typeface face1=Typeface.createFromAsset(con1.getAssets(),\"arial.ttf\");
forgot_password.setTypeface(face1);
// new theTask().execute();
login_button=(ImageButton)findViewById(R.id.login);
sign_button=(ImageButton)findViewById(R.id.signup);
login_button.setonClickListener(new OnClickListener(){
public void onClick(View v) {
String username,password;
emailid =(EditText)findViewById(R.id.edemail);
epassword =(EditText)findViewById(R.id.edpassword);
username = emailid.getText().toString();
password = epassword.getText().toString();
showDialog(0);
// Todo Auto-generated method stub
SoapObject request=new SoapObject(NAMESPACE,METHOD_NAME);
String qry=\"{\\\"General\\\":\"+\"{\\\"type\\\": \\\"Request\\\",\"+\"\\\"application\\\": \\\"Mmmmm\\\",\"+\"\\\"appver\\\": \\\"1.0.0\\\",\"+\"\\\"phonedeviceid\\\": \\\"123456789\\\",\"+\"\\\"deviceType\\\": \\\"Android\\\",\"+\"\\\"deviceOsversion\\\": \\\"3.0\\\"},\"+\"\\\"Login\\\":\"+\"{\\\"emailID\\\":\"+\"\\\"\"+username+\"\\\",\"+\"\\\"password\\\":\"+\"\\\"\"+password+\"\\\"\"+\"}\"+\"}\";
Log.i(\"Input\",qry);
request.addProperty(\"JSONRequestString\",qry);
SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.bodyOut=request;
envelope.encodingStyle=SoapSerializationEnvelope.ENC2001;
envelope.setoutputSoapObject(request);
AndroidHttpTransport androidHttpTransPort= new AndroidHttpTransport(URL);
try
{
try {
androidHttpTransPort.call(SOAP_ACTION,envelope);
} catch (IOException e) {
// Todo Auto-generated catch block
e.printstacktrace();
}
SoapPrimitive rest=(SoapPrimitive)envelope.getResponse();
Log.i(\"output\",\"Result\"+rest );
// SoapObject var = (SoapObject)rest.getProperty(0);
String conv=rest.toString();
JSONObject js=new JSONObject(conv);
String login = js.getString(\"Login\");
JSONObject err=new JSONObject(login);
String messcode=js.getString(\"HomePageFooterNewUpdates\");
JSONObject code=new JSONObject(messcode);
int GetMessageCode=code.getInt(\"noOfMail\");
Log.i(\"message code \",\"is \" +GetMessageCode);
// String errc=err.getString(\"errorMsg\");
// Log.i(\"err\",errc);
int ResponseForLogin=err.getInt(\"errorCode\");
Log.i(\"Response \",\"is \"+ResponseForLogin);
if(ResponseForLogin==000){
Toast.makeText(Login.this,\"Login Successfull\",Toast.LENGTH_LONG).show();
// prepare the dialog Box
/* ProgressDialog dialog = new ProgressDialog(this);
// make the progress bar Cancelable
dialog.setCancelable(true);
// set a message text
dialog.setMessage(\"Loading...\");
// show it
dialog.show();*/
Intent i=new Intent(Login.this,Home.class);
i.putExtra(\"messcode\",GetMessageCode);
startActivity(i);
} else {
Toast.makeText(Login.this,\"Invalid Emailid or Password...Please Try Again\",Toast.LENGTH_LONG).show();
}
}catch (XmlPullParserException e) {
e.printstacktrace();
}
catch (JSONException e) {
// Todo Auto-generated catch block
e.printstacktrace();
} catch (SoapFault e) {
// Todo Auto-generated catch block
e.printstacktrace();
}
}
} );
sign_button.setonClickListener(new OnClickListener(){
public void onClick(View v) {
Intent i=new Intent(Login.this,Signup.class);
startActivity(i);
}
});
}
}
提前致谢...
解决方法
仅给您一些提示,请尝试从中获取帮助。
ImageButton login=(ImageButton)findViewById(R.id.Login);
EditText editText1=(EditText)findViewById(R.id.emailText);
EditText editText2=(EditText)findViewById(R.id.passwordText);
login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if((editText1.getText()+\" \").trim().equals(\"\") || editText1.getText() == null || (editText2.getText()+\" \").trim().equals(\"\") || editText2.getText() == null ){
//show error message here
}
else{
//perrform your action here
//either start a new activity or do something else
}
}
});
希望这会帮助你。
,我发现以下教程绝对可以帮助我使用这些资源来实现正确的登录和注册屏幕:
材料设计
共享首选项
PHP脚本
MySQL数据库
SQLlite数据库
这是本教程的链接。
我知道这已经很晚了,但希望对您有所帮助。