Android按钮不响应OnClickListener:

Android按钮不响应OnClickListener:,android,login,android-studio,httprequest,onclicklistener,Android,Login,Android Studio,Httprequest,Onclicklistener,这是我在这里的第一篇帖子。。。我正在学习android编程来制作应用程序。我曾尝试过在线学习教程,首先让我的应用程序与我设置的服务器通信,以便用户从sql数据库登录。 然而,在我的登录按钮似乎没有做任何事情。 以下是物流活动: package com.tazo.zegga.app; import ... public class LoginActivity extends PlusBaseActivity implements LoaderCallbacks<Cursor&g

这是我在这里的第一篇帖子。。。我正在学习android编程来制作应用程序。我曾尝试过在线学习教程,首先让我的应用程序与我设置的服务器通信,以便用户从sql数据库登录。 然而,在我的登录按钮似乎没有做任何事情。 以下是物流活动:

    package com.tazo.zegga.app;

import ...


public class LoginActivity extends PlusBaseActivity implements LoaderCallbacks<Cursor>{
    String response = null;
    TextView  txt_Error;

    public void login (View view) {
        EditText txt_uname=(EditText)findViewById(R.id.email);
        EditText txt_pwd=(EditText)findViewById(R.id.password);

        String uname=txt_uname.getText().toString();
        String pwd=txt_pwd.getText().toString();
        UserLoginTask task = new UserLoginTask(uname, pwd);
        task.execute(uname, pwd);
    }
        public final static String EXTRA_RESULT = "com.tazo.zegga.result";

    // UI references.
    private AutoCompleteTextView mEmailView;
    private EditText mPasswordView;
    private View mProgressView;
    private View mEmailLoginFormView;
    private SignInButton mPlusSignInButton;
    private View mSignOutButtons;
    private View mLoginFormView;

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


        // Set up the login form.
        mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
        populateAutoComplete();

        mPasswordView = (EditText) findViewById(R.id.password);
        mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
                if (id == R.id.login || id == EditorInfo.IME_NULL) {
                    attemptLogin();
                    return true;
                }
                return false;
            }
        });

        Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button);
        mEmailSignInButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                attemptLogin();


            }
        });

        mLoginFormView = findViewById(R.id.login_form);
        mProgressView = findViewById(R.id.login_progress);
        mEmailLoginFormView = findViewById(R.id.email_login_form);
        mSignOutButtons = findViewById(R.id.plus_sign_out_buttons);
    }

    private void populateAutoComplete() {
        getLoaderManager().initLoader(0, null, this);
    }


    /**
     * Attempts to sign in or register the account specified by the login form.
     * If there are form errors (invalid email, missing fields, etc.), the
     * errors are presented and no actual login attempt is made.
     */
    public void attemptLogin() {

        if (mAuthTask != null) {
            return;
        }


        // Reset errors.
        mEmailView.setError(null);
        mPasswordView.setError(null);

        // Store values at the time of the login attempt.
        String email = mEmailView.getText().toString();
        String password = mPasswordView.getText().toString();

        boolean cancel = false;
        View focusView = null;

        UserLoginTask task = new UserLoginTask(email,password);
        task.execute(email, password);




    }
    private boolean isEmailValid(String email) {
        //TODO: Replace this with your own logic
        return email.contains("@");
    }

    private boolean isPasswordValid(String password) {
        //TODO: Replace this with your own logic
        return password.length() > 4;
    }



    /**
     * Represents an asynchronous login/registration task used to authenticate
     * the user.
     */
    public class UserLoginTask extends AsyncTask<String, Void, String> {

        private final String mEmail;
        private final String mPassword;


        UserLoginTask(String email, String password) {
            mEmail = email;
            mPassword = password;
        }

        @Override
        protected String doInBackground(String... params) {
            // TODO: attempt authentication against a network service.
            ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
            postParameters.add(new BasicNameValuePair("username", params[0] ));
            postParameters.add(new BasicNameValuePair("password", params[1] ));
            String res = null;
            try {
                response = CustomHttpClient.executeHttpPost("http://192.168.1.50/zegga/v1/index.php/login", postParameters);
                res=response.toString();
                res= res.replaceAll("\\s+","");
            }
            catch (Exception e) {
                txt_Error.setText(e.toString());
            }
            return res;
        }//close doInBackground


        }


        protected void onPostExecute(String result) {
            mAuthTask = null;
            showProgress(false);
            Intent intentLogin = new Intent(LoginActivity.this, MainActivity.class);
            intentLogin.putExtra(EXTRA_RESULT, result);
            startActivity(intentLogin);

        }


        protected void onCancelled() {
            mAuthTask = null;
            showProgress(false);
        }
    }
package com.tazo.zegga.app;
进口
公共类LoginActivity扩展了PlusBaseActivity,实现了LoaderCallbacks{
字符串响应=null;
文本视图txt_错误;
公共无效登录(查看){
EditText txt_uname=(EditText)findviewbyd(R.id.email);
EditText txt_pwd=(EditText)findviewbyd(R.id.password);
字符串uname=txt_uname.getText().toString();
字符串pwd=txt_pwd.getText().toString();
用户登录任务=新用户登录任务(uname,pwd);
任务执行(uname,pwd);
}
公共最终静态字符串EXTRA_RESULT=“com.tazo.zegga.RESULT”;
//用户界面引用。
私有AutoCompleteTextView mEmailView;
私有编辑文本mPasswordView;
私有视图mProgressView;
私有视图mEmailLoginFormView;
私人登录按钮mPlusSignInButton;
私有视图按钮;
私有视图mloginfo视图;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u登录);
//设置登录表单。
mEmailView=(AutoCompleteTextView)findviewbyd(R.id.email);
populateAutoComplete();
mPasswordView=(EditText)findViewById(R.id.password);
mPasswordView.setOnEditorActionListener(新的TextView.OnEditorActionListener(){
@凌驾
公共布尔onEditorAction(TextView TextView、int id、KeyEvent KeyEvent){
if(id==R.id.login | | id==EditorInfo.IME_NULL){
尝试登录();
返回true;
}
返回false;
}
});
按钮mEmailSignInButton=(按钮)findViewById(R.id.email\u sign\u in\u按钮);
setOnClickListener(新的OnClickListener()){
@凌驾
公共void onClick(视图){
尝试登录();
}
});
mLoginFormView=findviewbyd(R.id.login\u表单);
mProgressView=findviewbyd(R.id.login\u progress);
mEmailLoginFormView=findviewbyd(R.id.email\u login\u表单);
mSignOutButtons=findviewbyd(R.id.plus\u sign\u out\u按钮);
}
私有void populateAutoComplete(){
getLoaderManager().initLoader(0,null,this);
}
/**
*尝试登录或注册登录表单指定的帐户。
*如果存在表单错误(无效电子邮件、缺少字段等),则
*出现错误,未进行实际登录尝试。
*/
public void attemptLogin(){
if(mAuthTask!=null){
回来
}
//重置错误。
mEmailView.setError(null);
mPasswordView.setError(null);
//在尝试登录时存储值。
字符串email=mEmailView.getText().toString();
字符串密码=mPasswordView.getText().toString();
布尔取消=假;
视图焦点视图=空;
UserLoginTask=新的UserLoginTask(电子邮件、密码);
任务。执行(电子邮件、密码);
}
私有布尔值isEmailValid(字符串电子邮件){
//TODO:用您自己的逻辑替换它
返回电子邮件。包含(“@”);
}
私有布尔值isPasswordValid(字符串密码){
//TODO:用您自己的逻辑替换它
返回密码。长度()>4;
}
/**
*表示用于身份验证的异步登录/注册任务
*用户。
*/
公共类UserLoginTask扩展异步任务{
私有最终字符串mEmail;
私有最终字符串mPassword;
UserLoginTask(字符串电子邮件、字符串密码){
mEmail=电子邮件;
mPassword=密码;
}
@凌驾
受保护的字符串doInBackground(字符串…参数){
//TODO:尝试对网络服务进行身份验证。
ArrayList后参数=新的ArrayList();
添加(新的BasicNameValuePair(“用户名”,参数[0]);
添加(新的BasicNameValuePair(“密码”,参数[1]);
字符串res=null;
试一试{
响应=CustomHttpClient.executeHttpPost(“http://192.168.1.50/zegga/v1/index.php/login“,后参数);
res=response.toString();
res=res.replaceAll(“\\s+”,”);
}
捕获(例外e){
txt_Error.setText(例如toString());
}
返回res;
}//封闭式背景
}
受保护的void onPostExecute(字符串结果){
mAuthTask=null;
显示进度(假);
Intent intentLogin=新Intent(LoginActivity.this,MainActivity.class);
intentLogin.putExtra(额外结果,结果);
startActivity(intentLogin);
}
受保护的void onCancelled(){
mAuthTask=null;
显示进度(假);
}
}
提前谢谢


编辑:删除了与G+登录相关的代码。。。感谢CodeMagic指出这里不需要我的大部分代码…

在您调用signIn()方法的mPlusSignInButton按钮的OnClickListener中。然而,没有这样的方法

如果您希望用户通过Google+登录,而不是使用登录按钮,则应使用Google+登录按钮


请参阅在Android应用程序中实现Google+登录按钮。

代码太多了,我的朋友!我没有看到你的
signIn()
方法,但我可能在其他方面迷失了方向。我使用并编辑了