Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

206
Visualizações
What is the type of this kind of declaration?

I am trying to learn Android. I have some Java experience but have never seen a code block like this one:

        addNumsButton.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            EditText firstNumEditText = (EditText) findViewById(R.id.firstNumEditText);
            EditText secNumEditText = (EditText) findViewById(R.id.secNumEditText);
            TextView resultTextView = (TextView) findViewById(R.id.resultTextView);
            resultTextView.setText((Integer.parseInt(firstNumEditText.getText().toString()) + Integer.parseInt(secNumEditText.getText().toString())) + "");
        }
    });

What is getting declared after the View.OnClickListener()? I checked that View.OnClickListener() returns type Interface.

What does the code after that method is used for?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

That's an anonymous class. It's special syntax for creating an instance of an abstract type by providing implementations right at the point of declaration. It's very common in GUI code (Android, Swing, what have you) to provide GUI action callbacks.

What your snippet is doing is pass an ad-hoc instance of View.OnClickListener to setOnClickListener that executes the code in the innermost brace block when the button is clicked.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda