High reuse of the bottom navigation bar
The bottom navigation bar is often used, so a demo is written, which uses the singleton mode and is highly modular.
Design a management class in the navigation bar and a separate layout file in the navigation bar (use the include label to load it to other pages)
Management class: Manage a radiogroup
Package com. example. manage; import java. util. randomAccess; import com. example. reuse_headbotton.R; import android. app. activity; import android. content. context; import android. widget. radioButton; import android. widget. radioGroup; public class BottomManager {RadioGroup rg; RadioButton news1, news2, news3, news4;/** Singleton mode, ensure that only one class exists to process all calls */public static BottomManager bottomManager = new BottomManager (); public static BottomManager getInstance () {return bottomManager;}/** find the component, to set the listener, you must manually call */public void initsDate (Activity ac) {rg = (RadioGroup) ac. findViewById (R. id. id_radiogroup); rg. setOnCheckedChangeListener (new LRadioGroupListener ();}/** listener set for radiogroup. L is the distinction I added myself * perform your calls on the adaptation interface, or you can pass a group of data */class LRadioGroupListener implements RadioGroup. onCheckedChangeListener {public void onCheckedChanged (RadioGroup group, int checkedId) {System. out. println (print the current button + checkedId); switch (checkedId) {case R. id. id_news: // TODO: match the task break of Button 1; case R. id. id_news2: // TODO: match the break of Button 2; case R. id. id_news3: // TODO: match the task break done by button 3; case R. id. id_news4: // TODO: match what the previous button 4 does. break; default: break ;}}}}
Layout file in the navigation bar