Android Long press event and click event Problem handling, Onitemlongclicklistener and Onitemclicklistener

Source: Internet
Author: User

Today, when doing demo, we need to set the long press and click events of the ListView item, Onitemlongclicklistener and Onitemclicklistener, however, the Click event can be implemented, and the long time operation will trigger the Click event simultaneously. Then look at the relevant source of Android, you can see the system is the priority of the corresponding Clicklisener, he is no return value. For Onitemlongclicklistener, there is a return value identifier. For a long press operation, if False is returned, 2 Lisener are appropriate, and if true, the system only handles long-press events.

Therefore, if you want your onitemlongclicklistener to take effect as long as the event is, you need to set the return value to true.

Here is the source code

    /**     * Interface definition for a callback to is invoked when an item in this     * Adapterview have been clicked.     */Public    interface Onitemclicklistener {        /**         * Callback method to is invoked when a item in this Adapterview Has         * been clicked.         * <p>         * Implementers can call Getitematposition (position) if they need         * To access the data associated with The selected item.         *         * @param parent The Adapterview where the click happened.         * @param view the view within the Adapterview that is clicked (this         * 'll be            A view provided by the adapter) 
   * @param position the position of the view in the adapter.         * @param ID of the row ID of the item that is clicked.         *        /void Onitemclick (adapterview<?> parent, view view, int position, long ID);    }


    /**     * Interface definition for a callback to being invoked when an item in this     * view has been clicked and held.
   
    */Public    interface Onitemlongclicklistener {        /**         * Callback method to being invoked when a item in this view H As been         * clicked and held.         *         * Implementers can call Getitematposition (position) if they need to access         * The data associated with the Selec Ted Item.         *         * @param parent The Abslistview where the click happened         * @param view the view within the Abslistview that WA S clicked         * @param position the position of the view in the list         * @param ID of the row ID of the item that is CLI cked         * Source has been explained here, if the return value is set to True, then the system consumes the long press event         * @return True if the callback consumed the long click, False otherwise         *        /Boolean Onitemlongclick (adapterview<?> parent, view view, int position, long ID);    }
   


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Long press event and click event Problem handling, Onitemlongclicklistener and Onitemclicklistener

Related Article

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.