High reuse of the bottom navigation bar

Source: Internet
Author: User

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

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.