Android 安卓的意图不起作用?

Android 安卓的意图不起作用?,android,android-intent,login,Android,Android Intent,Login,我正在为android开发一个登录注册应用程序,我已经创建了一个示例帐户,但每当我单击“登录”按钮时,什么都没有发生? 有什么问题吗?logcat上什么也没出现 我的java代码 import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.wid

我正在为android开发一个登录注册应用程序,我已经创建了一个示例帐户,但每当我单击“登录”按钮时,什么都没有发生? 有什么问题吗?logcat上什么也没出现

我的java代码

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class HomeActivity extends Activity 
{
    Button btnSignIn,btnSignUp;
    LoginDataBaseAdapter loginDataBaseAdapter;

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

         // create a instance of SQLite Database
         loginDataBaseAdapter=new LoginDataBaseAdapter(this);
         loginDataBaseAdapter=loginDataBaseAdapter.open();




            }


    // Methos to handleClick Event of Sign In Button
    public void onClick(View V)
       {


            // get the Refferences of views
            final  EditText editTextUserName=(EditText)findViewById(R.id.editTextUserNameToLogin);
            final  EditText editTextPassword=(EditText)findViewById(R.id.editTextPasswordToLogin);

            Button btnSignIn=(Button)findViewById(R.id.buttonSignIn);

            // Set On ClickListener
            btnSignIn.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    // get The User name and Password
                    String userName=editTextUserName.getText().toString();
                    String password=editTextPassword.getText().toString();

                    // fetch the Password form database for respective user name
                    String storedPassword=loginDataBaseAdapter.getSinlgeEntry(userName);

                    // check if the Stored password matches with  Password entered by user
                    if(password.equals(storedPassword))
                    {
                        Toast.makeText(HomeActivity.this, "Congrats: Login Successfull", Toast.LENGTH_LONG).show();

                        {
                            Intent intent = new Intent (v.getContext(), MainActivity.class);
                            startActivityForResult(intent, 0);
                        }
                        }
                    else
                    {
                        Toast.makeText(HomeActivity.this, "User Name or Password does not match", Toast.LENGTH_LONG).show();
                    }
                }
            });


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // Close The Database
        loginDataBaseAdapter.close();
    }
}
我的xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/editTextUserNameToLogin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="User Name"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/editTextPasswordToLogin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPassword"
        android:hint="Password" />

    <Button
        android:id="@+id/buttonSignIn"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Sign In" />

</LinearLayout>

您已经有了用于登录的onClick方法。在里面,您再次为同一个按钮设置OnClickListener

这是错误的

setContentView
之后的
onCreate
中尝试以下操作:

EditText editTextUserName=(EditText)findViewById(R.id.editTextUserNameToLogin);
EditText editTextPassword=(EditText)findViewById(R.id.editTextPasswordToLogin);

Button btnSignIn=(Button)findViewById(R.id.buttonSignIn);
btnSignIn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // get The User name and Password
        //your code of getting values, comparing and startActivity    
    }
});

希望这是清楚的。

`btnSignIn.setOnClickListener(新视图.OnClickListener(){`这在
onClick
方法中。您尚未在
onCreate()
(或
onResume()
)中设置侦听器。