Calling methods from another class

0

In case I need to call a method of another class to perform an insertion in the database and I have to pass an object of type Usuario as a parameter

Code:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.usuario);

    Button btn_gravar = (Button)findViewById(R.id.btn_gravar);

    EditText nome_usuario = (EditText)findViewById(R.id.edt_nome);
    EditText sexo_usuario = (EditText)findViewById(R.id.edt_sexo);
    EditText telefone_usuario = (EditText)findViewById(R.id.edt_telefone);
    EditText datanascimento_usuario = (EditText)findViewById(R.id.edt_datanasc);
    EditText datacadastro_usuario = (EditText)findViewById(R.id.edt_datacad);
    EditText cidade_usuario = (EditText)findViewById(R.id.edt_cidade);
    EditText endereco_usuario = (EditText)findViewById(R.id.edt_endereco);
    EditText cpf_usuario = (EditText)findViewById(R.id.edt_cpf);
    EditText rg_usuario = (EditText)findViewById(R.id.edt_rg);
    EditText email_usuario = (EditText)findViewById(R.id.edt_email);

    final Usuario usuario = new Usuario();
            usuario.nome = nome_usuario;
            usuario.sexo = sexo_usuario;
            usuario.telefone = telefone_usuario;
            usuario.datanascimento = datanascimento_usuario;
            usuario.datacadastro = datacadastro_usuario;
            usuario.cidade = cidade_usuario;
            usuario.endereco = endereco_usuario;
            usuario.cpf = cpf_usuario;
            usuario.rg = rg_usuario;
            usuario.email = email_usuario;

    btn_gravar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //Passando parâmetros da intent para o obj usuário
            Toast.makeText(getApplicationContext(), "Você foi cadastrado com sucesso!!!", Toast.LENGTH_LONG).show();

                CrudUsuario crudusuario;
                crudusuario = new CrudUsuario(usuario);
                crudusuario.insert(usuario);



        }
    });

} 
    
asked by anonymous 22.08.2015 / 02:13

1 answer

0

How is this method declared in the other class? you do not want to instantiate it in your code? Because the most "right" way is to declare an instance of the class inside.

If you do not want to instantiate a way, you declare the method as static there in the class where the method is written, there you do not have to declare the class, you just need the same amount. Of course on the other side he has to be ready to receive an object as a parameter.

    
22.08.2015 / 02:41