0
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);
         btnLogin.setOnClickListener(new OnClickListener() {

             @Override
             public void onClick(View v) {            
                     Intent myIntent = new Intent(v.getContext(), AddName.class);
                     startActivityForResult(myIntent, 0);
                 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(); 
                     }
                       }
                          });

 }           
       }

アプリのログインページを作成しました。パスワードとユーザー名が一致する場合、エミュレーターで実行しているときに次の画面に移動する必要がありますが、これを実行しているときにユーザー名とパスワードが間違っている場合、アプリは2番目のページに移動します誰でも提案できます

4

3 に答える 3

1
package com.app.NewProjectHttpDemo;

import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

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);
         btnLogin.setOnClickListener(new OnClickListener() {

             @Override
             public void onClick(View v) {            

                 if((txtUserName.getText().toString()).equals(txtPassword.getText().toString())){
 Intent myIntent = new Intent(v.getContext(), AddName.class);
                     startActivityForResult(myIntent, 1);
                     Toast.makeText(LoginappActivity.this, "Login Successful",Toast.LENGTH_LONG).show();
                    } else{
                     Toast.makeText(LoginappActivity.this, "Invalid Login",Toast.LENGTH_LONG).show(); 
                     }
                       }
                          });

 }           
       }

このコードをあなたのコードに置き換えてください。これは完全に機能します

于 2012-05-08T13:34:07.233 に答える
0
 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);

     btnLogin.setOnClickListener(new OnClickListener() {

         @Override
         public void onClick(View v) {            

             if((txtUserName.getText().toString()).equals(txtPassword.getText().toString())){
                 Intent firstIntent = new Intent(v.getContext(), SecondActivity.class);
                 startActivity(firstIntent);

                } else{
                        Intent secondtIntent = new Intent(v.getContext(),SecondActivity.class);
                 startActivity(secondIntent);
                 }
                   }
                      });

}
}

于 2012-05-08T11:54:33.850 に答える
0
         btnLogin=(Button)this.findViewById(R.id.btnLogin);
         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();

                     Intent myIntent = new Intent(v.getContext(), AddName.class);
                     startActivity(myIntent);

                    } else{
                     Toast.makeText(LoginappActivity.this, "Invalid Login",Toast.LENGTH_LONG).show(); 
                     }
                   }
               });
于 2012-05-08T12:02:18.837 に答える