Use the Kotlin library in Java… here is a solution to the problem.
Use the Kotlin library in Java
I’m trying to use the GitHub library (MeowBottomNavigation) in Android Studio. But it’s written in kotlin, and I can’t use the listeners in it.
The only thing given is this
bottomNavigation.setOnShowListener {
}
bottomNavigation.setOnClickMenuListener {
}
Recommended display use
(Function 1).
I’m not sure how to implement it in java. Any help would be appreciated.
I’m 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;
}
});
Solution
Function0、Function1、Function2 … FunctionN is a higher-order function in kotlin.
After converting to Java, your click listener will look like this.
// 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;
}
});