title: In a Login page compare a hard codded value to username , password given as input
body: <p>I am working on the Login page of an application. I want to compare a hard codded value to username , password given as input. 
  Lines of code currently used is: </p>
  
  <pre><code>    usr = (EditText) findViewById(R.id.usr);   
        pwd = (EditText) findViewById(R.id.pwd);    
       error = (TextView) findViewById(R.id.tv_error);     
      String n1="i077653" ;  
        if(n1.equals(usr.getText().toString()) &amp;&amp; pwd.equals("1234"))    
       {          error.setText("login success");     }         
       else     {      error.setText("LOGIN failed");         }
   .
  </code></pre>
  
  <p>But its not working .Can you suggest a solution for this ?</p>
  
  <p>complete code :
  XML file :</p>
  
  <pre><code>XML file :&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context=".MainActivity" &gt;
  
      &lt;TextView
          android:id="@+id/textView1"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true"
          android:background="#FF6633"
          android:paddingLeft="60dp"
          android:paddingRight="100dp"
          android:text="@string/SA" /&gt;
  
      &lt;TextView
          android:id="@+id/tv_pw"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignBaseline="@+id/pwd"
          android:layout_alignBottom="@+id/pwd"
          android:layout_alignLeft="@+id/tv_un"
          android:text="Password:"
          android:textColor="#444444"
          android:textSize="7pt" /&gt;
  
      &lt;TextView
          android:id="@+id/tv_un"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignBaseline="@+id/usr"
          android:layout_alignBottom="@+id/usr"
          android:layout_alignParentLeft="true"
          android:text="User Name:"
          android:textColor="#444444"
          android:textSize="7pt" /&gt;
  
      &lt;EditText
          android:id="@+id/usr"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/btn_login"
          android:layout_below="@+id/textView1"
          android:layout_marginTop="20dp"
          android:ems="7"
          android:hint="@string/User" &gt;
  
          &lt;requestFocus /&gt;
      &lt;/EditText&gt;
  
      &lt;EditText
          android:id="@+id/pwd"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/usr"
          android:layout_below="@+id/usr"
          android:layout_marginTop="18dp"
          android:ems="7"
          android:hint="@string/Pwd"
          android:inputType="textPassword" /&gt;
  
      &lt;Button
          android:id="@+id/btn_login"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/pwd"
          android:layout_marginTop="18dp"
          android:layout_toRightOf="@+id/tv_un"
  
          android:text="@string/Button" /&gt;
  &lt;TextView
          android:id="@+id/tv_error"
          android:layout_width="fill_parent"
          android:layout_height="40dip"
          android:textSize="7pt"
          android:layout_alignParentLeft="true"
          android:layout_below="@id/btn_login"
          android:layout_marginRight="9dip"
          android:layout_marginTop="15dip"
          android:layout_marginLeft="15dip"
          android:textColor="#AA0000"
          android:text=""/&gt;
  
  
  
     &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Java file:</p>
  
  <pre><code>package com.example.survey;
  
  import android.os.Bundle;
  
  import android.app.Activity;
  import android.text.Editable;
  import android.view.Menu;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.TextView;
  
  
  public class MainActivity extends Activity {
      EditText usr ;
      EditText pwd ;
      Button  log;
      TextView error;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  
     public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
      public void  check(View view){
      usr = (EditText) findViewById(R.id.usr);
      pwd = (EditText) findViewById(R.id.pwd);
      error = (TextView) findViewById(R.id.tv_error);
      String n1="i077653" ;
  
  
      if(n1.equalsIgnoreCase(usr.getText().toString()) &amp;&amp; pwd.equalsIgnoreCase("1234"))    
      {          error.setText("login success");     }         
      else     {      error.setText("LOGIN failed");         }
  
  
      }
      }
  </code></pre>