I want to add clickListener
to all specific item item1, item2, item3
and I want to set separate fragment on this. can anyone please help me to set onClickListener
in every item.
This is my code:
public class BottomNavigation extends AppCompatActivity {
private FrameLayout frameLayout;
private AHBottomNavigation bottomNavigation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bottom_navigation);
frameLayout = (FrameLayout) findViewById(R.id.main_frame);
final AHBottomNavigation bottomNavigation=(AHBottomNavigation) findViewById(R.id.bottom_navigation);
final AHBottomNavigationItem item1 =
new AHBottomNavigationItem("Home",
R.drawable.ic_home_black_24dp);
AHBottomNavigationItem item2 =
new AHBottomNavigationItem("Home",
R.drawable.ic_home_black_24dp);
final AHBottomNavigationItem item3 =
new AHBottomNavigationItem("Home",
R.drawable.ic_home_black_24dp);
AHBottomNavigationItem item4 =
new AHBottomNavigationItem("Home",
R.drawable.ic_home_black_24dp);
AHBottomNavigationItem item5 =
new AHBottomNavigationItem("Home",
R.drawable.ic_home_black_24dp);
bottomNavigation.addItem(item1); //specific listener for all these items
bottomNavigation.addItem(item5);
bottomNavigation.addItem(item4);
bottomNavigation.addItem(item3);
bottomNavigation.addItem(item2);
bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_SHOW);
bottomNavigation.setOnTabSelectedListener(new AHBottomNavigation.OnTabSelectedListener() {
@Override
public void onTabSelected(int position, boolean wasSelected) {
// fragment.updateColor(Color.parseColor(colors[position]));
}
});
}
}