我正在为我的应用创建注册页面。我在下面的代码EditEmail
,EditPass
,EditRepass
,EditMobile
中有4个文本字段。我已经创建了登录页面,现在我需要对我的登录代码进行一些更改才能使注册页面正常工作。但我认为我犯了一些错误。在login
我有一个复选框,但在此代码中它不是必需的。我不知道如何处理checbox代码。我想将上述4个字段发送到我的远程服务器,并检查在用户注册之前是否未使用“email id”。我应该如何使下面的代码完美。
public class SignUpActivity extends Activity
{
EditText editEmail, editPass, editRepass, editMobile;
Button submit,exit;
String name = "", pass = "", repass = "", mobile = "";
SharedPreferences app_preferences;
Intent i;
CheckBox check;
byte[] data;
HttpPost httppost;
HttpResponse response;
HttpClient httpclient;
StringBuffer buffer;
InputStream inputStream;
List<NameValuePair> nameValuePairs;
@Override
public void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.signup);
submit = (Button) findViewById(R.id.submit);
exit = (Button) findViewById(R.id.exit);
editEmail=(EditText)findViewById(R.id.editEmail);
editPass=(EditText)findViewById(R.id.editPass);
editRepass=(EditText)findViewById(R.id.editRepass);
editMobile=(EditText)findViewById(R.id.editMobile);
app_preferences = PreferenceManager.getDefaultSharedPreferences(this);
check = (CheckBox) findViewById(R.id.check);
String Str_user = app_preferences.getString("username", "0");
String Str_pass = app_preferences.getString("password", "0");
String Str_repass = app_preferences.getString("repassword", "0");
String Str_mobile = app_preferences.getString("mobile", "0");
String Str_check = app_preferences.getString("checked", "no");
if (Str_check.equals("yes")) {
editTextId.setText(Str_user);
editTextP.setText(Str_pass);
check.setChecked(true);
}
submit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
name = editEmail.getText().toString();
pass = editPass.getText().toString();
repass = editRepass.getText().toString();
mobile = editMobile.getText().toString();
String Str_check2 = app_preferences.getString("checked", "no");
if (Str_check2.equals("yes")) {
SharedPreferences.Editor editor = app_preferences.edit();
editor.putString("username", name);
editor.putString("password", pass);
editor.putString("repassword", repass);
editor.putString("umobile", mobile);
editor.commit();
}
if (name.equals("") || pass.equals("") || repass.equals("") || mobile.equals("") ) {
Toast.makeText(SignUpActivity.this, "Blank Field..Please Enter", Toast.LENGTH_SHORT).show();
} else {
}
}
});
exit.setOnClickListener(new View.OnClickListener ()
{
public void onClick(View v)
{
finish();
}
});
}
public void Move_to_next1()
{
startActivity(new Intent(SignUpActivity.this, SplashActivity.class));
finish();
}
@SuppressLint("NewApi")
private class LoginTask extends AsyncTask <Void, Void, String>
{
@SuppressLint("NewApi")
@Override
protected void onPreExecute()
{
super.onPreExecute();
// Show progress dialog here
}
@Override
protected String doInBackground(Void... arg0) {
try {
httpclient = new DefaultHttpClient();
httppost = new HttpPost("http://abc.com/login1.php");
// Add your data
nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("UserEmail", name.trim()));
nameValuePairs.add(new BasicNameValuePair("Password", pass.trim()));
nameValuePairs.add(new BasicNameValuePair("RePassword", repass.trim()));
nameValuePairs.add(new BasicNameValuePair("Mobile", mobile.trim()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
response = httpclient.execute(httppost);
inputStream = response.getEntity().getContent();
data = new byte[256];
buffer = new StringBuffer();
int len = 0;
while (-1 != (len = inputStream.read(data))) {
buffer.append(new String(data, 0, len));
}
inputStream.close();
return buffer.toString();
}
catch (Exception e)
{
e.printStackTrace();
}
return "";
}
@SuppressLint("NewApi")
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
// Hide progress dialog here
if (buffer.charAt(0) == 'Y')
{
Toast.makeText(SignUpActivity.this, "Succesfully Registered", Toast.LENGTH_SHORT).show();
Move_to_next1();
}
else
{
Toast.makeText(SignUpActivity.this, " E-Mail Already Registered", Toast.LENGTH_SHORT).show();
}
}
}
}