roughike / BottomBar

(Deprecated) A custom view component that mimics the new Material Design Bottom Navigation pattern.
Apache License 2.0
8.43k stars 1.51k forks source link

Switch to middle bar when a listview item is selected in left bar #841

Open moeharoon opened 6 years ago

moeharoon commented 6 years ago

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.

  1. Clicked on Quail Valley course (Inital load image)
  2. Opens the Log fragment ( middle bottombuton)
  3. Click Enter Score Open fragment scoringFragment (Not showing anything)

initalload

step2

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.java courseList.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.java View.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(); } };

fenrirx22 commented 6 years ago

please, provide the code with proper formatting :)

wangerekaharun commented 6 years ago

@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.