按钮可点击但不起作用

Button is clickable but doesn't work

所以我有这个代码,但是当我在我的 phone 上尝试它时没有做任何事情..
我也在 firebase 网站上尝试过该版本,但它不起作用。如果你们能帮助我,我将不胜感激!

我认为这是 the problem 有人可以帮我吗?

public class LoginActivity extends AppCompatActivity {

    public Firebase mFirebase;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Firebase.setAndroidContext(this);
        mFirebase = new Firebase("https://kip.firebaseio.com");
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_login);
    }

    public void onClickLogin(View v){

        final String email = ((EditText) findViewById(R.id.email)).getText().toString();
        final String password =((EditText) findViewById(R.id.password)).getText().toString();

        mFirebase.createUser(email, password, new Firebase.ResultHandler() {
            @Override
            public void onSuccess() {
                mFirebase.authWithPassword(email, password, null);
                System.out.println("Successfully created user account!");
            }

            @Override
            public void onError(FirebaseError firebaseError) {
                mFirebase.authWithPassword(email, password, null);
                System.out.println("There was an error connecting!");
            }
        });

    }

}

这是我的XML

<Button 
    android:layout_width="300dp" 
    android:layout_height="wrap_content" 
    android:background="@drawable/button_login" 
    android:text="@string/login" 
    android:textColor="@android:color/white" 
    android:textSize="16sp" 
    android:id="@+id/button"
    android:layout_below="@+id/password"  
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="75dp" 
    android:onClick="onClickLogin" 
    android:clickable="true" />

试试:

public class LoginActivity extends AppCompatActivity {

    public Firebase mFirebase;
    Button button = (Button) findViewById(R.id.button);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Firebase.setAndroidContext(this);
        mFirebase = new Firebase("https://kip.firebaseio.com");
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        button.setOnClickListener( new OnClickListener() {

            @Override
            public void onClick(View v) {

                final String email = ((EditText) findViewById(R.id.email)).getText().toString();
                final String password =((EditText) findViewById(R.id.password)).getText().toString();

                mFirebase.createUser(email, password, new Firebase.ResultHandler() {
                    @Override
                    public void onSuccess() {
                        mFirebase.authWithPassword(email, password, null);
                        System.out.println("Successfully created user account!");
                    }

                    @Override
                    public void onError(FirebaseError firebaseError) {
                        mFirebase.authWithPassword(email, password, null);
                        System.out.println("There was an error connecting!");
                    }
                });



            }
        });


        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_login);
    }


}

这是最终代码,它有效!!

protected EditText mEmail;
protected EditText mPassword;
protected Button mLogin;
protected Button mRegister;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Firebase.setAndroidContext(this);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_login);

    mEmail = (EditText) findViewById(R.id.email);
    mPassword = (EditText) findViewById(R.id.password);
    mLogin = (Button) findViewById(R.id.Login);
    mRegister = (Button) findViewById(R.id.Register);

    mLogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Firebase ref = new Firebase("https://kip.firebaseio.com");

            String email = mEmail.getText().toString().trim();
            String password = mPassword.getText().toString().trim();

            ref.authWithPassword(email, password, new Firebase.AuthResultHandler() {
                @Override
                public void onAuthenticated(AuthData authData) {
                    System.out.println("User ID: " + authData.getUid() + ", Provider: " + authData.getProvider());
                    Intent activity = new Intent(LoginActivity.this, HomeActivity.class);
                    startActivity(activity);

                }
                @Override
                public void onAuthenticationError(FirebaseError firebaseError) {
                    // there was an error
                }
            });

        }
    });

    mRegister.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Firebase ref = new Firebase("https://kip.firebaseio.com");

            String email = mEmail.getText().toString().trim();
            String password = mPassword.getText().toString().trim();

            ref.createUser(email, password, new Firebase.ValueResultHandler<Map<String, Object>>() {
                @Override
                public void onSuccess(Map<String, Object> result) {
                    System.out.println("Successfully created user account with uid: " + result.get("uid"));
                }

                @Override
                public void onError(FirebaseError firebaseError) {
                    // there was an error
                }
            });


        }
    });

}

}