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

351
Visualizações
Using Kotlin Library in java

I am trying to use a GitHub library (MeowBottomNavigation)in Android Studio.But its written in kotlin and i cant use the listeners in it. The only thing which is given is this

bottomNavigation.setOnShowListener {
}

bottomNavigation.setOnClickMenuListener {
}

the suggestions shows to use

(Function1)

i am not sure as to how to implement this in java . Any help will be appreciated.

I am familiar with java but the library is written in Kotlin. Is there any way to use these listeners in java?

bottomNavigation.setOnClickMenuListener(new 
Function1<MeowBottomNavigation.Model, Unit>() {
        @Override
        public Unit invoke(MeowBottomNavigation.Model p1) {
            int i = p1.getId();
            switch (i){
                case 4:
                    Toast.makeText(UserMainActivity.this, i, Toast.LENGTH_SHORT).show();
                    break;
                case  1:
                    Toast.makeText(UserMainActivity.this, i, Toast.LENGTH_SHORT).show();
                    break;
                case 2:
                    Toast.makeText(UserMainActivity.this, i, Toast.LENGTH_SHORT).show();
                    break;
                case 3:
                    Toast.makeText(UserMainActivity.this, i, Toast.LENGTH_SHORT).show();
                    break;
            }
            return Unit.INSTANCE;
        }
    });
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Function0, Function1, Function2, ... FunctionN are higher-order functions in kotlin.

After converting to java, your click listeners become something like below.

// Set Menu Click Listener 
bottomNavigation.setOnClickMenuListener(new Function1<MeowBottomNavigation.Model, Unit>() {
        @Override
        public Unit invoke(MeowBottomNavigation.Model p1) {
            return Unit.INSTANCE;
        }
    });

// Set Menu Show listener
bottomNavigation.setOnShowListener(new Function1<MeowBottomNavigation.Model, Unit>() {
        @Override
        public Unit invoke(MeowBottomNavigation.Model s) {
            return Unit.INSTANCE;
        }
    });
over 4 years ago · Santiago Trujillo Relatório

0

something like This::

bottomNavigation.setOnShowListener( new IBottomNavigationListener(Model model)
{


} );
over 4 years ago · Santiago Trujillo Relatório

0

if you are using fragments

//1.-declare fragments globally in your activity

private HomeFragment homeFragment = new HomeFragment();

//2.- declare a method to switch between fragments

public void loadFragment(Fragment fragment){
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.yourFragmentContainer,fragment);
        transaction.commit();
    }

//3.- in the Set Menu Click/show Listener call the fragment to show

// Set Menu Click Listener







      bottomNavigation.setOnClickMenuListener(new Function1<MeowBottomNavigation.Model, Unit>() {
                @Override
                public Unit invoke(MeowBottomNavigation.Model model) {
                    int i = model.getId();
                    switch (i){
                        case  1:
                            loadFragment(homeFragment);
                            break;
                            //...other cases
    
                    }
                    return Unit.INSTANCE;
                }
            });
        
        // Set Menu Show listener
        bottomNavigation.setOnShowListener(new Function1<MeowBottomNavigation.Model, Unit>() {
                @Override
                public Unit invoke(MeowBottomNavigation.Model model) {
                    int i = model.getId();
                    switch (i){
                        case  1:
                            loadFragment(homeFragment);
                            break;
                            //...other cases
                    }
                    return Unit.INSTANCE;
                }
            });
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