Open moeharoon opened 6 years ago
please, provide the code with proper formatting :)
@moeharoon had the same problem on issue #829 and am yet to get a solution.
I tried selectTabAtPositon(2,false)
but it was not behaving properly...it created two instances of
the fragment and i did not prefer this way cause my fragment was updating itself with time record and this was messy. So if your fragment only handles static data you can use this hack.
I have a 3 tab bottombar(course,log,stats). Course tab is populated with listView items. when click the the item in listview, it sends data and opens log fragment. but it does not defaults to log bottom bar. Please see attachment. I'm sure there is a simple solution, I must not be doing it right, THanks in advance for your help.
Use case.
Code: MainActivity.java
bottomBar = (BottomBar) findViewById(R.id.bottomBar); bottomBar.setOnTabSelectListener(new OnTabSelectListener() { @Override public void onTabSelected(@IdRes int tabId) { if (tabId==R.id.tab_courses_id){ transaction = manager.beginTransaction(); transaction.add(R.id.contentContainer2,courseFragment,"courseFragment"); transaction.addToBackStack(null); transaction.commit(); } if (tabId == R.id.tab_scorelog_id) { transaction = manager.beginTransaction(); transaction.replace(R.id.contentContainer2,logScoreFragment,"logScoreFragment"); transaction.addToBackStack(null); transaction.commit(); } if (tabId == R.id.tab_stats_id) { transaction = manager.beginTransaction(); transaction.replace(R.id.contentContainer2,statsFragment,"statsFragment"); transaction.addToBackStack(null); transaction.commit(); } } }); bottomBar.setOnTabReselectListener(new OnTabReselectListener() { @Override public void onTabReSelected(@IdRes int tabId) { if (tabId == R.id.tab_courses_id) { transaction = manager.beginTransaction(); transaction.replace(R.id.contentContainer2,courseFragment,"courseFragment"); transaction.addToBackStack(null); transaction.commit(); } if (tabId == R.id.tab_scorelog_id) { transaction = manager.beginTransaction(); transaction.replace(R.id.contentContainer2,logScoreFragment,"logScoreFragment"); transaction.addToBackStack(null); transaction.commit(); } if (tabId == R.id.tab_stats_id) { transaction = manager.beginTransaction(); transaction.replace(R.id.contentContainer2,statsFragment,"statsFragment"); transaction.addToBackStack(null); transaction.commit(); } } });
CourseFragment.javacourseList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> p, View v, int position, long id) { Bundle b = new Bundle(); b.putString("coursename",course.getName()); Fragment logScore = new LogScoreFragment(); logScore.setArguments(b); FragmentManager manager = getFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.contentContainer2,logScore); transaction.addToBackStack(null); transaction.commit();
LogFragment.javaView.OnClickListener btnListener = new View.OnClickListener() { @Override public void onClick(View v) { Bundle b = new Bundle(); b.putString("coursename",cousename); ... ... Fragment scoring = new ScoringFragment(); scoring.setArguments(b); FragmentManager manager = getFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.contentContainer2,scoring); transaction.addToBackStack(null); transaction.commit(); } };