aurelhubert / aurelhubert/ahbottomnavigation
getItemViewPosition always return null but not under OnTabSelectedListener
- Dominant language
- Java
- Stars
- 3.8k
- Forks
- 672
- PR merge metrics
- No merged PRs in 30d
Description
I found out something interesting the getItemViewPosition always return null after added all the items, but it won't return null if I put under setOnTabSelectedListener.
Here is the code snippet
homepageTab.setTitleState(AHBottomNavigation.TitleState.ALWAYS_SHOW);
homepageTab.setAccentColor(getResources().getColor(R.color.colorPrimary));
homepageTab.setForceTint(true);
AHBottomNavigationItem item1 = new AHBottomNavigationItem("Questions",
R.drawable.survey_tab_icon);
AHBottomNavigationItem item2 = new AHBottomNavigationItem("Nearby",R.drawable.peoplenearby );
AHBottomNavigationItem item3 = new AHBottomNavigationItem("Chat",
R.drawable.message_selector);
AHBottomNavigationItem item4 = new AHBottomNavigationItem("Me", R.drawable.me_selector);
ArrayList< AHBottomNavigationItem> itemArrayList = new ArrayList<>();
itemArrayList.add(item1);
itemArrayList.add(item2);
itemArrayList.add(item3);
itemArrayList.add(item4);
// Add items
homepageTab.addItems(itemArrayList);
homepageTab.setCurrentItem(0);
// for smooth swipe
viewPager.setOffscreenPageLimit(3);
Log.d("HomePage123","OutSide tabSelected " + homepageTab.getViewAtPosition(0) );
// Set listeners
homepageTab.setOnTabSelectedListener(new AHBottomNavigation.OnTabSelectedListener() {
@Override
public boolean onTabSelected(int position, boolean wasSelected) {
viewPager.setCurrentItem(position,false);
homepageTab.getViewAtPosition(0);
Log.d("HomePage123","Under tabSelected " + homepageTab.getViewAtPosition(0) );
return true;
}
});
Here is the log output :

Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing getViewAtPosition and the view initialization performed by addItems, then compare the call timing before and inside OnTabSelectedListener. Reproduce the logged behavior with the provided four-item setup and determine whether the method should return a view immediately after addItems; done means the behavior is consistent and covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100