android在登录应用程序之间切换两个意图

时间:2012-05-08 07:47:46

标签: android

 @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);
        btnLogin=(Button)this.findViewById(R.id.btnLogin);
        btnLogin.setOnClickListener(new OnClickListener() {

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

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

       };

    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(); 
           }
             }

    }

我创建了一个登录应用程序,可以从一个意图转换到另一个意图。另一个.java工作正常

  • error1:令牌上的语法错误,而是预期的注释名称

  • 错误2:此行的多个标记
             - Syntax error, insert "EnumBody" to complete EnumDeclaration
             - Syntax error, insert "enum Identifier" to complete EnumHeaderName
             - Syntax error, insert ")" to complete Expression
             - Syntax error, insert "}" to complete ClassBody

2 个答案:

答案 0 :(得分:3)

}}函数末尾有一些额外的onClick。它应该是:

next.setOnClickListener(new View.OnClickListener() {   

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

顺便说一句,我发现另一个onClickListener中onClickListener的使用非常混乱。你应该将它们分开。

答案 1 :(得分:1)

一定是这样的:

@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);
    Button btnLogin = (Button) this.findViewById(R.id.btnLogin);

    btnLogin.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if ((txtUserName.getText().toString()).equals(txtPassword.getText()
            .toString())) {
        Toast.makeText(DelActivity.this, "Login Successful",
                Toast.LENGTH_LONG).show();
    } else {
        Toast.makeText(DelActivity.this, "Invalid Login",
                Toast.LENGTH_LONG).show();
    }
        }
    });

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

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

}