Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Button
- android:id="@+id/bSignup"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="#FF0000"
- android:text="Sign Up"
- android:textColor="#FFFFFF"
- android:textSize="20sp"
- android:textStyle="bold" />
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_signup);
- final EditText etEmail = (EditText) findViewById(R.id.etEmail);
- final EditText etUsername = (EditText) findViewById(R.id.etUsername);
- final EditText etPassword = (EditText) findViewById(R.id.etPassword);
- final Button bSignup = (Button) findViewById(R.id.bSignup);
- bSignup.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- final String username = etUsername.getText().toString();
- final String email = etEmail.getText().toString();
- final String password = etPassword.getText().toString();
- Response.Listener<String> responseListener = new Response.Listener<String>(){
- @Override
- public void onResponse(String response) {
- try {
- JSONObject jsonResponse = new JSONObject(response);
- boolean success = jsonResponse.getBoolean("success");
- if (success){
- Intent intent = new Intent(Signup.this, Signin.class);
- Signup.this.startActivity(intent);
- }else {
- AlertDialog.Builder builder = new AlertDialog.Builder(Signup.this);
- builder.setMessage("Sign up failed")
- .setNegativeButton("Retry", null)
- .create()
- .show();
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- };
- SignupRequest signupRequest = new SignupRequest(username, email, password, responseListener);
- RequestQueue queue = Volley.newRequestQueue(Signup.this);
- queue.add(signupRequest);
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement