Question

this java code allows to proceed to next activity even if no data is enetered. add...

this java code allows to proceed to next activity even if no data is enetered. add a constraint which displays a message to fill all fields.


import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class SignupActivity extends AppCompatActivity {

    EditText editTextName,editTextEmail,editTextPhone,editTextPswd,editTextCPswd,editTextAge,editTextFatherName;
    Button btnMoveToLogin;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_signup);
        editTextName=findViewById(R.id.editTextName);
        editTextFatherName=findViewById(R.id.editTextFatherName);
        editTextAge=findViewById(R.id.editTextAge);
        editTextPhone=findViewById(R.id.editTextPhoneNumber);
        editTextPswd=findViewById(R.id.editTextPswd);
        editTextCPswd=findViewById(R.id.editTextCPswd);
        editTextEmail=findViewById(R.id.editTextEmail);
        btnMoveToLogin=findViewById(R.id.buttonMoveToLogIn);
        btnMoveToLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i("Name",editTextEmail.getText().toString());
                if(editTextEmail.getText().toString()=="" && editTextFatherName.getText().toString()=="" && editTextPhone.getText().toString()=="" && editTextPswd.getText().toString()=="" && editTextCPswd.getText().toString()=="" && editTextName.getText().toString()=="" && editTextAge.getText().toString()==""){
                    Toast.makeText(SignupActivity.this, "Please enter all the fields", Toast.LENGTH_SHORT).show();
                    return;
                }
                if(editTextCPswd.getText().toString()==editTextPswd.getText().toString()){
                    Toast.makeText(SignupActivity.this, "Passwords do not match!!", Toast.LENGTH_SHORT).show();
                }else{
                    Intent intent=new Intent(SignupActivity.this, LoginActivity.class);
                    startActivity(intent);
                }
            }
        });
    }
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class SignupActivity extends AppCompatActivity {

EditText editTextName,editTextEmail,editTextPhone,editTextPswd,editTextCPswd,editTextAge,editTextFatherName;
Button btnMoveToLogin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
editTextName=findViewById(R.id.editTextName);
editTextFatherName=findViewById(R.id.editTextFatherName);
editTextAge=findViewById(R.id.editTextAge);
editTextPhone=findViewById(R.id.editTextPhoneNumber);
editTextPswd=findViewById(R.id.editTextPswd);
editTextCPswd=findViewById(R.id.editTextCPswd);
editTextEmail=findViewById(R.id.editTextEmail);
      
btnMoveToLogin=findViewById(R.id.buttonMoveToLogIn);
  
       btnMoveToLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i("Name",editTextEmail.getText().toString());
              
               // if any of the text field is not populated , show toast message
               // trim is used to remove trailing and leading spaces
               // length is used to return the number of characters in the string
if(editTextEmail.getText().toString().trim().length() == 0 || editTextFatherName.getText().toString().trim().length() == 0 || editTextPhone.getText().toString().trim().length() == 0 || editTextPswd.getText().toString().trim().length() == 0 || editTextCPswd.getText().toString().trim().length() == 0 || editTextName.getText().toString().trim().length() == 0 ||
               editTextAge.getText().toString().trim().length() == 0){
Toast.makeText(SignupActivity.this, "Please enter all the fields", Toast.LENGTH_SHORT).show();
  
}else{
                   // if passwords do not match, show toast message
                   if(!editTextCPswd.getText().toString().equals(editTextPswd.getText().toString()))
                   {
                       Toast.makeText(SignupActivity.this, "Passwords do not match!!", Toast.LENGTH_SHORT).show();
                   }else{
                       // All fields are populated and passwords match, hence proceed to the next activity
                       Intent intent=new Intent(SignupActivity.this, LoginActivity.class);
                       startActivity(intent);
                   }
}
}
});
}
}

Add a comment
Know the answer?
Add Answer to:
this java code allows to proceed to next activity even if no data is enetered. add...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Edit question this login java code allows to proceed to next activity even if no data...

    Edit question this login java code allows to proceed to next activity even if no data is enetered. add a constraint which displays a message to fill all fields. package com.example.Divahalls; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; public class LoginActivity extends AppCompatActivity { Button btnMoveToDashboard; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); btnMoveToDashboard=findViewById(R.id.buttonMoveToDashboard); btnMoveToDashboard.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(LoginActivity.this,CustomerActivity.class); startActivity(intent); } }); } }

  • this customer java code allows to proceed to next activity even if no data is enetered....

    this customer java code allows to proceed to next activity even if no data is enetered. add a constraint which displays a message to fill all fields. import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.Spinner; import android.widget.SpinnerAdapter; import java.util.ArrayList; import java.util.List; public class CustomerActivity extends AppCompatActivity { EditText editTextName, editTextEmail,editTextPhone, editTextMenu; Button btnBook; Spinner s; String packageName; SpinnerAdapter spinnerAdapter; List<String> packages=new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_customer);...

  • Adroid Studio Error View.setOnClickListener Error: Class 'anonymous class derived from OnClickListener ' must either be declared...

    Adroid Studio Error View.setOnClickListener Error: Class 'anonymous class derived from OnClickListener ' must either be declared abstract or implement abstract method 'onClick(View)' in 'OnClickListener ' @Override Error: Method does not override method from its superclass package com.example.gregorybacon.assignment_1; import android.content. Intent; import android. support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view. View; import android.widget.Button; public class MainScreen extends AppCompatActivity f @0verride protected void onCreate(Bundle savedInstanceState) ( super.onCreate(savedInstanceState); setContentView(R. layout.activity main_screen); Button button_unlock-(Button) findViewById(R.id.button_unlock); button_unlock.setOnClickListener(new View.OnClickListener) L aoverride public void OnClick(View view) startActivity(new Intent( packageContext:...

  • Getting prob in following code.Can anybody suggest how to write if/else if I want to show...

    Getting prob in following code.Can anybody suggest how to write if/else if I want to show hint as username/Paswword required if null and password or username did not match if entered wrong and go to next activity if its right.?? public class MainActivity extends AppCompatActivity { EditText userName, pwd; DatabaseHelper helper = new DatabaseHelper(this); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void onClickOk(View v) { if (v.getId() == R.id.LogIn) { final EditText User = (EditText) findViewById(R.id.userName); String...

  • I should show tables with info after clicking on the buttons in Android Studio. I still...

    I should show tables with info after clicking on the buttons in Android Studio. I still can not get what I should write inside OnClick function and how to use containers for printing tables. Please help me! import androidx.appcompat.app.AppCompatActivity; import android.content.Context; import android.os.Bundle; import android.text.Layout; import android.view.LayoutInflater; import android.view.View; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; import java.util.ArrayList; public class MainActivity extends AppCompatActivity { LinearLayout container; ListView ListView1; ListView ListView2; ListView ListView3; @Override protected void onCreate(Bundle savedInstanceState)...

  • Need help to edit the code below. Am using it play a lottery game in Android...

    Need help to edit the code below. Am using it play a lottery game in Android Studio what i need help with is if play one game u need to clear it up before u could another game. Here is my activity_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="simpleapps.my.lotteryapplication.MainActivity" android:orientation="vertical" android:layout_margin="10dp" android:weightSum="100"> <TextView android:layout_width="match_parent" android:layout_height="0dp" android:text="Enter White Balls : " android:textColor="#000000" android:textSize="22sp" android:layout_weight="15" /> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:orientation="horizontal" android:weightSum="100" android:layout_margin="10dp" android:layout_weight="15"> <EditText android:id="@+id/wBall1" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="20" android:inputType="number"/>...

  • Need help to edit the code below. Am using it play a lottery game in Android...

    Need help to edit the code below. Am using it play a lottery game in Android Studio what i need help with is if play one game u need to clear it up before u could another game. Here is my activity_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="simpleapps.my.lotteryapplication.MainActivity" android:orientation="vertical" android:layout_margin="10dp" android:weightSum="100"> <TextView android:layout_width="match_parent" android:layout_height="0dp" android:text="Enter White Balls : " android:textColor="#000000" android:textSize="22sp" android:layout_weight="15" /> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:orientation="horizontal" android:weightSum="100" android:layout_margin="10dp" android:layout_weight="15"> <EditText android:id="@+id/wBall1" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="20" android:inputType="number"/>...

  • Why is my app crashing? Following is an app that takes notes from users and shows...

    Why is my app crashing? Following is an app that takes notes from users and shows it's encrypted string. It also decrypt and encrypted strings. It saves the note in a file and also loads it back. Please help me identify what I am doing wrong? activity_krypto_note.xml <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".KryptoNoteActivity"> <EditText android:id="@+id/key" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:ems="10" android:hint="Cryptographic Key" android:inputType="number" app:layout_constraintEnd_toStartOf="@+id/encrypt" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <Button android:id="@+id/encrypt" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:onClick="enryptClicked" android:text="ENCRYPT" android:textSize="9sp"...

  • Package is.hi.hbv601g.mathstermind; import android.content.Intent; import android.os.Handler; im...

    package is.hi.hbv601g.mathstermind; import android.content.Intent; import android.os.Handler; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import com.google.firebase.auth.FirebaseAuth; import is.hi.hbv601g.mathstermind.model.MyDataHelper; public class PlayGameActivity extends AppCompatActivity { private static final int easyQuestionNumber = 4; private static final int mediumQuestionNumber = 4; private static final int hardQuestionNumber = 4; private static final String[] easyQuestions = {"1+2 =", "7-2 =", "5*3 =", "12/4="}; private static final String[][] easyAnswers = { {"3", "4", "6", "1"}, {"5", "8", "9", "4"}, {"10", "8", "15",...

  • I am working on integrating a database to an Android application for a course. Currently, I have all the database code done, but getting all of the EditText fields to enter data into the database has...

    I am working on integrating a database to an Android application for a course. Currently, I have all the database code done, but getting all of the EditText fields to enter data into the database has me stuck. Assignment objectives here, so we can be on the same page: Create a second page with a data entry form and the following fields: recipename, category, ingredients, and instructions. Make the Category field a dropdown box that contains the recipe categories listed...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT