1

アプリのサインアップページを作成しています。以下のコードEditEmailに4 つのテキスト フィールドがあります。すでにログイン ページを作成しましたが、サインアップ ページが機能するようにログイン コードを変更する必要があります。でもミスは少なかったと思います。私はチェックボックスを持っていますが、このコードでは必須ではありません。チェックボックスコードの扱い方がわかりません。上記の4つのフィールドをリモートサーバーに送信し、ユーザーが登録される前に「メールID」が使用されていないかどうかを確認したい. 次のコードを完璧にするにはどうすればよいですか。EditPassEditRepassEditMobilelogin

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();
                }
            }
        }   
}
4

0 に答える 0