lundi 5 septembre 2016

If block not working in Android

In the given code my all ifs are working normally but the one in which i am checking if cp1.equals(p1) is not working. Even the Toast is not showing up. I am new to Android. Please help

     public void onClick(View view) {

        EditText u = (EditText) findViewById(R.id.username1);
        EditText p = (EditText) findViewById(R.id.password1);
        EditText cp = (EditText) findViewById(R.id.cpassword);
        EditText id=(EditText)findViewById(R.id.id);
        String u1=u.getText().toString();
        String p1=p.getText().toString();
        String e=id.getText().toString();
        String cp1=cp.getText().toString();


        if ((u1.equals("")) || (p1.equals("")) || cp1.equals("")||e.equals("")) {

            Toast.makeText(this, "No field can be left empty!!", Toast.LENGTH_LONG).show();
        }



        if(cp1.equals(p1)){
            Toast.makeText(this,"check",Toast.LENGTH_SHORT).show();

            dbHelper = new DBHelper(this);
            newDB=dbHelper.getWritableDatabase();
            newDB.execSQL("INSERT INTO "+tablename+" VALUES ('"+u1+"', '"+p1+"', '"+e+"' );");
            Toast.makeText(this,"SUCCESSFULLY REGISTERED!",Toast.LENGTH_SHORT).show();
            Intent i = new Intent(register1.this,MainActivity.class);
            startActivity(i);
             }
         if (cp1.equals(p1)==false)
        {

                       Toast.makeText(this,"Confirm PAssword and password fields should be equal",Toast.LENGTH_SHORT).show();
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire