2012-05-08 85 views
0
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 


    txtUserName=(EditText)this.findViewById(R.id.txtUname); 
    txtPassword=(EditText)this.findViewById(R.id.txtPwd); 
    btnLogin=(Button)this.findViewById(R.id.btnLogin); 

      Button btnLogin=(Button)this.findViewById(R.id.Button01); 
     btnLogin.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       if((txtUserName.getText().toString()).equals(txtPassword.getText().toString())){ 
         Toast.makeText(LoginappActivity.this, "Login Successful",Toast.LENGTH_LONG).show(); 
       } 
       else 
       { 
         Toast.makeText(LoginappActivity.this, "Invalid Login",Toast.LENGTH_LONG).show(); 
       } 
       } 
      } 
     ); 

      Button next = (Button) findViewById(R.id.Button01); 
      next.setOnClickListener(new View.OnClickListener() { 

       public void onClick(View view) { 
       Intent myIntent = new Intent(view.getContext(), AddName.class); 
       startActivityForResult(myIntent, 0); 
      }});  
     }  
} 

當應用程序在模擬器中運行時,它已成功編譯,但我不知道是否有成功的登錄或無效登錄。我無法看到應用程序是否成功登錄

回答

0

如果寫入... Else內部按鈕單擊事件。

Button btnLogin=(Button)this.findViewById(R.id.Button01); 
     btnLogin.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       if((txtUserName.getText().toString()).equals(txtPassword.getText().toString())){ 
         Toast.makeText(LoginappActivity.this, "Login Successful",Toast.LENGTH_LONG).show(); 
       } 
       else 
       { 
         Toast.makeText(LoginappActivity.this, "Invalid Login",Toast.LENGTH_LONG).show(); 
       } 
       } 
      } 
     }); 
1

您需要將此代碼放入Login按鈕的onClickListner中。修改的頌歌應該是

​​
+0

@Abhinai你接受的答案與我的答案有什麼區別?我的回答是在其他答案之前發佈的,但仍選擇該答案! – Antrromet

+0

我只能選擇一個答案,因此在點擊上述答案時切換 – Abhinai

相關問題