"Android" Navigationview head Click Listener Event

Source: Internet
Author: User

Androidstudio gives the template only list click events, that is, to implement the Onnavigationitemselected method in Onnavigationitemselectedlistener, Depending on the ID of item, click on which item is clicked. However, the template does not give the header a click event.

The method is to add the head dynamically, with the following code:

// Navigationview Head Click event Bindings        View Drawview = Navigationview.inflateheaderview (r.layout.nav_header_main);         = (ImageButton) Drawview.findviewbyid (R.ID.HEAD_IV);        Head_iv.setonclicklistener (new  View.onclicklistener () {            @Override            public  void  OnClick (View v) {                log.d ("Log:", "the head is clicked!") ");            }        });

Attention!! Since it has been added dynamically, the following sentence in XML must be deleted, or there will be two headers in the case, as shown in 1.

app:headerlayout= "@layout/nav_header_main"

Figure 1

"Android" Navigationview head Click Listener Event

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.