I am new at Android development for my final year project. I have encounter some problem that second activity which is Parent Login Activity Page submit button is not working well as it should be done error checking before moving to another activity page.
Main Activity.java code
public class MainActivity extends AppCompatActivity implements View.OnClickListener{ //DEFINE WHICH BUTTON TO CLICK ON Button ButtonParent; Button ButtonKid; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButtonParent=findViewById(R.id.buttonParent); ButtonKid=findViewById(R.id.buttonKid); ButtonParent.setOnClickListener(this); ButtonKid.setOnClickListener(this); } @Override public void onClick(View view) { if (view==ButtonParent) { Intent intent_Parent = new Intent(MainActivity.this, ParentLogin.class); intent_Parent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent_Parent); }else if(view==ButtonKid) { Intent intent_Kid = new Intent(MainActivity.this, KidLogin.class); intent_Kid.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent_Kid); } } }
Parent Login.java Code
public class ParentLogin extends AppCompatActivity implements View.OnClickListener{ EditText pName; EditText pNRIC; Button ParentLogin; Button ParentRegister; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_parent_login); pName = findViewById(R.id.LoginParentName); pNRIC = findViewById(R.id.ParentNRIC); ParentLogin=findViewById(R.id.LoginParentSubmit); ParentRegister=findViewById(R.id.LoginParentRegister); ParentLogin.setOnClickListener(this); ParentRegister.setOnClickListener(this); } @Override public void onClick(View view) { if (view == ParentLogin) { String ParentName = pName.getText().toString().trim(); String ParentNRIC = pNRIC.getText().toString().trim(); boolean res = ParentDAO.checkParent(ParentName, ParentNRIC); if ((TextUtils.isEmpty(ParentName))||!(TextUtils.isEmpty(ParentNRIC))) { Toast toast= Toast.makeText(ParentLogin.this, "Please fill in all the empty columns which are available", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL,0,0); toast.show(); } else { if (res) { Toast.makeText(ParentLogin.this, "Login Successfully", Toast.LENGTH_SHORT).show(); Intent intent_parentActivity = new Intent(ParentLogin.this, ParentActivity.class); intent_parentActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent_parentActivity); } else { Toast.makeText(ParentLogin.this, "Login not Successfully", Toast.LENGTH_SHORT).show(); } } }else if(view==ParentRegister) { Intent intent_parentRegister = new Intent(ParentLogin.this, ParentRegistration.class); intent_parentRegister.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent_parentRegister); } } } https://stackoverflow.com/questions/65746618/second-activitys-button-jump-back-to-main-activity-which-it-shouldnt-be January 16, 2021 at 12:53PM
没有评论:
发表评论