method is never used

1

I have a doubt because this method never runs, there is no syntax error and it is well invoked but I can not understand why it never uses it. the "public void signIn" method

import android.app.Activity;
import android.app.Dialog;
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.activity_main);

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

    // Get The Refference Of Buttons
    btnSignIn=(Button)findViewById(R.id.buttonSignIN);
    btnSignUp=(Button)findViewById(R.id.buttonSignUP);

    // Set OnClick Listener on SignUp button
    btnSignUp.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // TODO Auto-generated method stub

            /// Create Intent for SignUpActivity  abd Start The Activity
            Intent intentSignUP=new Intent(getApplicationContext(),SignUPActivity.class);
            startActivity(intentSignUP);
        }
    });
}
// Methos to handleClick Event of Sign In Button
public void signIn(View V)
{
    final Dialog dialog = new Dialog(HomeActivity.this);
    dialog.setContentView(R.layout.iniciar_sesion);
    dialog.setTitle("Login");

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

    Button btnSignIn=(Button)dialog.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();
                dialog.dismiss();
            }
            else
            {
                Toast.makeText(HomeActivity.this, "User Name or Password does not match", Toast.LENGTH_LONG).show();
            }
        }
    });

    dialog.show();
}

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

}

    
asked by Diego 13.06.2016 в 17:46
source

2 answers

2
  

method is never used

Indicates that your method is not being used, I notice that your method is defined as:

  public void signIn(View V){

Check if you are calling your method signIn() from the layout from an element, if you really need the method add the property android:onClick

If you are calling from code, your method should be defined as:

public void signIn(){

To avoid the message you can add the annotation @SuppressWarnings("unused") :

@SuppressWarnings("unused")
public void signIn(View V){
...
...

but it is advisable to eliminate unnecessary code, ensure that your method is not actually used.

    
answered by 13.06.2016 / 17:59
source
-1

I had this same problem, researching I discovered that the fragment and the activity are different in the Java Class.

On this page I discovered the solution:   How to handle button clicks using the XML onClick within Fragments

    
answered by 22.07.2017 в 03:53