Could not find method connectionBanco(View) in a Parent or Ancestor Context for android:onClick attribute defined on view class

Asked

Viewed 247 times

1

package com.projeto.comandapack;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import static com.projeto.comandapack.R.id.txtCaminhoBd;
import static com.projeto.comandapack.R.id.txtSenhaBd;
import static com.projeto.comandapack.R.id.txtUsuarioBd;


public class ConfiguracaoActivity extends AppCompatActivity {

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

    }
    public void conexaoBanco(View view){

        final EditText caminhoBanco = findViewById(txtCaminhoBd);
        final EditText usuarioBd = findViewById(txtUsuarioBd);
        final EditText senhaBd = findViewById(txtSenhaBd);

        ConexaoBanco conexaoComBanco = new ConexaoBanco(caminhoBanco.getText().toString(),usuarioBd.getText().toString(), senhaBd.getText().toString());

                    if (conexaoComBanco.testaConexao())
                        Toast.makeText(getApplicationContext(), "Não foi possível conectar, reveja as informações", Toast.LENGTH_LONG).show();
                    else {
                        findViewById(txtCaminhoBd).setEnabled(false);
                        findViewById(txtUsuarioBd).setEnabled(false);
                        findViewById(txtUsuarioBd).setEnabled(false);
                        Toast.makeText(getApplicationContext(), "Conexão bem sucedida", Toast.LENGTH_LONG).show();
                    }
                }

    public void limpaConfig(View view){

        final EditText caminhoBanco = findViewById(txtCaminhoBd);
        final EditText usuarioBd = findViewById(txtUsuarioBd);
        final EditText senhaBd = findViewById(txtSenhaBd);

            caminhoBanco.setText("");
            usuarioBd.setText("");
            senhaBd.setText("");

            findViewById(txtCaminhoBd).setEnabled(true);
            findViewById(txtUsuarioBd).setEnabled(true);
            findViewById(txtUsuarioBd).setEnabled(true);
    }
    public void btnVoltar(View view){

            Intent it = new Intent(ConfiguracaoActivity.this, MainActivity.class);
            startActivity(it);

    }
}

1 answer

0

I managed to solve, it was on account of the way you’re calling this Activity, I changed the shape and the buttons started working.

Was:

Button abrirConfig = (Button) findViewById(R.id.btnConfig);

abrirConfig.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent it = new Intent(MainActivity.this, ConfiguracaoActivity.class);
            startActivity(it);
        }
    });

Within the OnCreate, I switched to:

Intent it = new Intent(getApplicationContext(), ConfiguracaoActivity.class);
startActivity(it);

and it worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.