正确编码后,登录按钮无响应

时间:2019-01-30 17:05:43

标签: java android

输入电子邮件和密码后,登录按钮将响应。应用程序中的所有其他按钮都可以正常工作,需要帮​​助。如何使我的登录按钮正常工作?

  package com.icmg.cs0480;

import android.app.ProgressDialog;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;

import java.util.Map;

public class DriverLoginRegisterActivity extends AppCompatActivity  {

    private Button DriverLoginButton;
    private Button DriverRegisterButton;
    private Button DriverRegisterLink;
    private EditText DriverEmail;
    private EditText DriverPassword;
    private ProgressDialog loadingBar;

    private FirebaseAuth mAuth;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_driver_login_register);

        mAuth = FirebaseAuth.getInstance();

        DriverLoginButton = findViewById(R.id.driver_login_btn);
        DriverRegisterButton = findViewById(R.id.driver_register_btn);
        DriverRegisterLink = findViewById(R.id.register_driver_link);
        TextView DriverStatus = findViewById(R.id.driver_status);
        DriverEmail = findViewById(R.id.driver_email);
        DriverPassword = findViewById(R.id.driver_password);
        loadingBar = new ProgressDialog(this);


        DriverRegisterButton.setVisibility(View.INVISIBLE);
        DriverRegisterButton.setEnabled(false);

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

                DriverLoginButton.setVisibility(View.INVISIBLE);
                DriverRegisterLink.setVisibility(View.INVISIBLE);


                DriverRegisterButton.setVisibility(View.VISIBLE);
                DriverRegisterButton.setEnabled(true);

                DriverRegisterButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        String email = DriverEmail.getText().toString();
                        String password = DriverPassword.getText().toString();

                        RegisterDriver(email, password);
                    }


                });

                    }
                });
                    }




    private void RegisterDriver(String email, String password) {
        if (TextUtils.isEmpty(email)) {
            Toast.makeText(DriverLoginRegisterActivity.this, "Please Write Email....", Toast.LENGTH_SHORT).show();
        }
        if (TextUtils.isEmpty(password)) {
            Toast.makeText(DriverLoginRegisterActivity.this, "Please Write Password....", Toast.LENGTH_SHORT).show();
        } else {
            loadingBar.setTitle("Driver Registration");
            loadingBar.setMessage("Please wait, While we register your data...");
            loadingBar.show();

            mAuth.createUserWithEmailAndPassword((email), password)
                    .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            if (task.isSuccessful()) {
                                Toast.makeText(DriverLoginRegisterActivity.this, "Driver Register Successfully... ", Toast.LENGTH_SHORT).show();
                                loadingBar.dismiss();

                                Intent driverIntent = new Intent(DriverLoginRegisterActivity.this, DriversMapsActivity.class);
                                startActivity(driverIntent);
                            } else {
                                Toast.makeText(DriverLoginRegisterActivity.this, "Driver Register Unsuccessful, Please try again... ", Toast.LENGTH_SHORT).show();
                                loadingBar.dismiss();
                            }
                        }
                    });

            DriverLoginButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String email = DriverEmail.getText().toString();
                    String password = DriverPassword.getText().toString();

                    DriverSignIn(email, password);}


    private void DriverSignIn(String email, String password) {   if (TextUtils.isEmpty(email)) {
        Toast.makeText(DriverLoginRegisterActivity.this, "Please Write Email....", Toast.LENGTH_SHORT).show();
    }
        if (TextUtils.isEmpty(password)) {
            Toast.makeText(DriverLoginRegisterActivity.this, "Please Write Password....", Toast.LENGTH_SHORT).show();
        } else {
            loadingBar.setTitle("Driver Login");
            loadingBar.setMessage("Please wait, While we check your credentials...");
            loadingBar.show();

            mAuth.signInWithEmailAndPassword((email), password)
                    .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            if (task.isSuccessful()) {
                                Toast.makeText(DriverLoginRegisterActivity.this, "Driver Login Successfully... ", Toast.LENGTH_SHORT).show();
                                loadingBar.dismiss();

                                Intent driverIntent = new Intent(DriverLoginRegisterActivity.this, DriversMapsActivity.class);
                                startActivity(driverIntent);
                            } else {
                                Toast.makeText(DriverLoginRegisterActivity.this, "Driver Login Unsuccessful, Please try again... ", Toast.LENGTH_SHORT).show();
                                loadingBar.dismiss();

        }}});}}});}}}

我希望登录名能够登录驱动程序并将其带到地图页面

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        tools:context=".GuestLoginRegisterActivity"
        android:orientation="vertical"
        android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="18dp"
    android:paddingRight="18dp"
    android:background="@drawable/new_login_gradients">



    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <!-- Here you can put your logo or brand name -->

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#f9d7db" />

        <ImageView
            android:id="@+id/logo"
            android:layout_width="match_parent"
            android:layout_height="289dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="20dp"
            android:layout_marginBottom="8dp"
            android:adjustViewBounds="true"
            android:cropToPadding="false"
            android:padding="16dp"
            android:scaleType="fitXY"
            android:src="@drawable/nhfclogo" />

        <TextView
            android:id="@+id/driver_status"
            android:layout_width="match_parent"
            android:layout_height="37dp"
            android:gravity="center_horizontal"
            android:text="DRIVER LOGIN"
            android:textColor="@android:color/background_light"
            android:textSize="30sp"
            android:textStyle="bold" />

        <EditText
            android:id="@+id/driver_email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="70dp"
            android:background="@android:color/transparent"
            android:drawableLeft="@drawable/ic_email"
            android:drawablePadding="12dp"
            android:ems="10"
            android:hint="Email"
            android:inputType="textEmailAddress"
            android:maxLines="1"
            android:padding="8dp"
            android:singleLine="false"
            android:textColorHint="#fff" />

        <EditText
            android:id="@+id/driver_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:background="@android:color/transparent"
            android:drawableLeft="@drawable/ic_lock_white_24dp"
            android:drawablePadding="12dp"
            android:ems="10"
            android:hint="......."
            android:inputType="textPassword"
            android:maxLines="1"
            android:padding="8dp"
            android:textColorHint="#fff" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#f9d7db" />

        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:padding="8dp"
            android:text="Remember me "
            android:textColor="#fff" />

        <Button
            android:id="@+id/driver_login_btn"
            style="@style/Base.TextAppearance.AppCompat.Body1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="24dp"
            android:background="@drawable/background_login"
            android:clickable="true"
            android:focusable="true"
            android:padding="16dp"
            android:text="Login"
            android:textAllCaps="false"
            android:textColor="#f16f7d"
            android:textSize="18sp"
            android:visibility="visible" />

        <Button
            android:id="@+id/register_driver_link"
            style="@style/Base.TextAppearance.AppCompat.Body1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:background="@drawable/background_signup"
            android:clickable="true"
            android:padding="16dp"
            android:text="Don't have a Account"
            android:textAllCaps="false"
            android:textColor="#fff"
            android:textSize="18sp"
            android:visibility="visible" />

        <TextView
            style="@style/TextAppearance.AppCompat.Body2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp"
            android:clickable="true"
            android:padding="16dp"
            android:text="Forget your Password? "
            android:textColor="#fff" />

        <Button
            android:id="@+id/driver_register_btn"
            style="@style/Base.TextAppearance.AppCompat.Body1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:background="@drawable/background_signup"
            android:clickable="true"
            android:padding="16dp"
            android:text="Register"
            android:textAllCaps="false"
            android:textColor="#fff"
            android:textSize="18sp"
            android:visibility="invisible" />

    </LinearLayout>
    </ScrollView>

</LinearLayout>

目录

01-31 18:55:31.502 18620-18643 / com.icmg.cs0480 V / FA:不活动,正在与服务断开连接 01-31 18:55:39.812 18620-18643 / com.icmg.cs0480 V / FA:记录用户参与度,毫秒:21593 01-31 18:55:39.812 18620-18643 / com.icmg.cs0480 V / FA:连接到远程服务 01-31 18:55:39.822 18620-18643 / com.icmg.cs0480 V / FA:活动已暂停,时间:95029052 01-31 18:55:39.832 18620-18643 / com.icmg.cs0480 D / FA:记录事件(FE):user_engagement(_e),Bundle [{firebase_event_origin(_o)= auto,engage_time_msec(_et)= 21593,firebase_screen_class (_sc)= DriverLoginRegisterActivity,firebase_screen_id(_si)= 2202821951799111479}]] 01-31 18:55:39.842 18620-18643 / com.icmg.cs0480 V / FA:连接尝试已在进行中 01-31 18:55:39.872 18620-18620 / com.icmg.cs0480 V / FA:onActivityCreated 01-31 18:55:40.482 18620-18643 / com.icmg.cs0480 D / FA:记录事件(FE):screen_view(_vs),Bundle [{firebase_event_origin(_o)= auto,firebase_previous_class(_pc)= DriverLoginRegisterActivity,firebase_previous_id (_pi)= 2202821951799111479,firebase_screen_class(_sc)= DriversMapsActivity,firebase_screen_id(_si)= 2202821951799111480}]] 01-31 18:55:40.532 18620-18643 / com.icmg.cs0480 V / FA:连接尝试已在进行中 01-31 18:55:40.532 18620-18643 / com.icmg.cs0480 V / FA:连接尝试已在进行中 01-31 18:55:40.532 18620-18643 / com.icmg.cs0480 V / FA:恢复了活动,时间:95029717 01-31 18:55:40.632 18620-18643 / com.icmg.cs0480 D / FA:已连接到远程服务 01-31 18:55:40.632 18620-18643 / com.icmg.cs0480 V / FA:处理排队的服务任务:4 01-31 18:55:40.672 2515-18372 /? V / FA-SVC:记录事件:origin = auto,名称= user_engagement(_e),params = Bundle [{firebase_event_origin(_o)= auto,engage_time_msec(_et)= 21593,firebase_screen_class(_sc)= DriverLoginRegisterActivity,firebase_screen_id(_si) = 2202821951799111479}] 01-31 18:55:40.702 2515-18372 /? V / FA-SVC:保存事件,名称,数据大小:user_engagement(_e),83 01-31 18:55:40.702 2515-18372 /? V / FA-SVC:记录的事件:事件{appId ='com.icmg.cs0480',名称='user_engagement(_e)',params =捆绑[{firebase_event_origin(_o)=自动,engage_time_msec(_et)= 21593,firebase_screen_class (_sc)= DriverLoginRegisterActivity,firebase_screen_id(_si)= 2202821951799111479}]} 01-31 18:55:40.702 2515-18372 /? V / FA-SVC:计划在大约ms内进行上传:3579318 01-31 18:55:40.702 2515-18372 /? V / FA-SVC:使用GcmTaskService安排上传 01-31 18:55:40.702 2515-18372 /? V / FA-SVC:使用Gcm计划任务。时间:3579318 01-31 18:55:40.722 2515-18372 /? V / FA-SVC:后台事件处理时间,毫秒:46 01-31 18:55:40.772 2515-18372 /? V / FA-SVC:记录事件:origin = auto,name = screen_view(_vs),params = Bundle [{firebase_event_origin(_o)= auto,firebase_previous_class(_pc)= DriverLoginRegisterActivity,firebase_previous_id(_pi)= 2202821951799111479,firebase_screen_class(_sc = DriversMapsActivity,firebase_screen_id(_si)= 2202821951799111480}] 01-31 18:55:40.822 2515-18372 /? V / FA-SVC:保存事件,名称,数据大小:screen_view(_vs),117 01-31 18:55:40.822 2515-18372 /? V / FA-SVC:记录的事件:事件{appId ='com.icmg.cs0480',名称='screen_view(_vs)',参数=捆绑[{firebase_event_origin(_o)=自动,firebase_previous_class(_pc)= DriverLoginRegisterActivity,firebase_previous_id (_pi)= 2202821951799111479,firebase_screen_class(_sc)= DriversMapsActivity,firebase_screen_id(_si)= 2202821951799111480}]} 01-31 18:55:40.822 2515-18372 /? V / FA-SVC:计划在大约ms的时间内上传:3579196 01-31 18:55:40.862 2515-18372 /? V / FA-SVC:使用GcmTaskService安排上传 01-31 18:55:40.862 2515-18372 /? V / FA-SVC:使用Gcm计划任务。时间:3579196 01-31 18:55:40.882 2515-18372 /? V / FA-SVC:后台事件处理时间,毫秒:117 01-31 18:55:41.042 18620-18648 / com.icmg.cs0480 D / FA:获取用户属性(FE) 01-31 18:55:43.972 18968-18968 /? V / FA:注册活动生命周期回调 01-31 18:55:44.232 18968-18990 / com.icmg.cs0480 V / FA:启用收藏 01-31 18:55:44.242 18968-18990 / com.icmg.cs0480 V / FA:应用包,谷歌应用ID:com.icmg.cs0480,1:513219199166:android:0d8e627edae5ac24 01-31 18:55:44.242 18968-18990 / com.icmg.cs0480 I / FA:应用程序测量正在启动,版本:14710 01-31 18:55:44.242 18968-18990 / com.icmg.cs0480 I / FA:要启用调试日志记录,请运行:adb shell setprop log.tag.FA VERBOSE 01-31 18:55:44.242 18968-18990 / com.icmg.cs0480 I / FA:要启用更快的调试模式事件记录,请运行:       亚行外壳setprop debug.firebase.analytics.app com.icmg.cs0480 01-31 18:55:44.242 18968-18990 / com.icmg.cs0480 D / FA:启用调试级别消息记录 01-31 18:55:44.272 18968-18990 / com.icmg.cs0480 V / FA:连接到远程服务 01-31 18:55:44.302 18968-18968 / com.icmg.cs0480 V / FA:onActivityCreated 01-31 18:55:44.312 18968-18990 / com.icmg.cs0480 V / FA:连接尝试已在进行中 01-31 18:55:44.592 18968-18990 / com.icmg.cs0480 I / FA:找不到标签管理器,因此将无法使用 01-31 18:55:44.602 18968-18990 / com.icmg.cs0480 D / FA:记录事件(FE):screen_view(_vs),Bundle [{firebase_event_origin(_o)= auto,firebase_screen_class(_sc)= DriverLoginRegisterActivity,firebase_screen_id (_si)= 2202821951799111479}] 01-31 18:55:44.642 18968-18990 / com.icmg.cs0480 V / FA:连接尝试已在进行中 01-31 18:55:44.652 18968-18990 / com.icmg.cs0480 V / FA:连接尝试已在进行中 01-31 18:55:44.652 18968-18990 / com.icmg.cs0480 V / FA:恢复了活动,时间:95033830 01-31 18:55:44.772 18968-18990 / com.icmg.cs0480 D / FA:已连接到远程服务 01-31 18:55:44.772 18968-18990 / com.icmg.cs0480 V / FA:处理排队的服务任务:4 01-31 18:55:44.802 2515-18372 /? V / FA-SVC:记录事件:origin = auto,name = screen_view(_vs),params = Bundle [{firebase_event_origin(_o)= auto,firebase_screen_class(_sc)= DriverLoginRegisterActivity,firebase_screen_id(_si)= 2202821951799111479}] 01-31 18:55:44.812 2515-18372 /? V / FA-SVC:保存事件,名称,数据大小:screen_view(_vs),72 01-31 18:55:44.822 2515-18372 /? V / FA-SVC:记录的事件:事件{appId ='com.icmg.cs0480',名称='screen_view(_vs)',params =捆绑[{firebase_event_origin(_o)=自动,firebase_screen_class(_sc)= DriverLoginRegisterActivity,firebase_screen_id (_si)= 2202821951799111479}]} 01-31 18:55:44.822 2515-18372 /? V / FA-SVC:预定的上传时间约为ms:3575199 01-31 18:55:44.832 2515-18372 /? V / FA-SVC:使用GcmTaskService安排上传 01-31 18:55:44.832 2515-18372 /? V / FA-SVC:使用Gcm计划任务。时间:3575199 01-31 18:55:44.842 2515-18372 /? V / FA-SVC:后台事件处理时间,毫秒:45 01-31 18:55:49.872 18968-18990 / com.icmg.cs0480 V / FA:不活动,正在断开服务 01-31 19:01:22.142 1775-1775 /? E / FirebaseInstanceId:无法解析目标意图服务,跳过了类名强制 01-31 19:01:22.142 1775-1775 /? E / FirebaseInstanceId:传递消息时出错:找不到ServiceIntent。

2 个答案:

答案 0 :(得分:1)

在操作之前,请先获取findViewById()的按钮。

 Button DriverLoginButton = findViewById(R.id.ur_button);

与此同时,请首先注释此行:

//Button DriverLoginButton = new Button(this);

答案 1 :(得分:0)

在layout.xml文件中创建按钮,提供按钮ID,并设置onClick属性,然后在Java文件中实现它。

由于您是直接在java文件中创建按钮,因此还需要将其手动添加到ViewGroup中,因此,如果您更喜欢GUI或XML文件,请改用设计编辑器。