-1
 EditText txtUserName;
 EditText txtPassword;
 Button btnLogin;
 Button btnCancel;

    /** Called when the activity is first created. */
 @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); 
            }});

       }

 }

在模拟器上运行此应用程序时,它运行良好,没有任何错误,但没有显示任何用户名和密码已成功记录或登录无效的消息,但是当我单击下一步按钮时,将显示下一个屏幕

4

2 回答 2

1

删除此行并检查它...

  Button  btnLogin=(Button)this.findViewById(R.id.Button01);<---------Remove it
于 2012-05-08T09:31:08.697 回答
0
       Button  btnLogin=(Button)this.findViewById(R.id.Button01);

       Button next = (Button) findViewById(R.id.Button01);

所以你在同一个按钮上有两个 onClickListeners。

于 2012-05-08T09:32:46.987 回答