baseadapter<t> rewrite Createviewfromresource Implement interface, refresh, load, remove

Source: Internet
Author: User

1   Importjava.util.ArrayList;2 Importjava.util.List;4 ImportAndroid.content.Context;5 ImportAndroid.view.LayoutInflater;6 ImportAndroid.view.View;7 ImportAndroid.view.ViewGroup;9 Importcom.lidroid.xutils.util.LogUtils;Ten  One /** A * Basic adapter, overriding Createviewfromresource implementation interface -  *  -  * @authorHZY the  * -  * @param<T> - * List of entities stored -  */ +  Public classBaseadapter<t>extendsAndroid.widget.BaseAdapter { -     PrivateContext Mcontext; +     PrivateLayoutinflater Minflater; A     PrivateList<t> Mdatas =NewArraylist<t>(); at  -      PublicBaseadapter (Context Mcontext, list<t>Mdatas) { -          This. Mcontext =Mcontext; -          This. Mdatas =Mdatas; -          This. Minflater =Layoutinflater.from (mcontext); -     } in  -      PublicContext GetContext () { to         return  This. Mcontext; +     } -  the      PublicLayoutinflater Getlayoutinflater () { *         return  This. Minflater; $     }Panax Notoginseng  -     /** the * Refresh A      * @paramMdatas the      */ +      Public voidRefresh (list<t>Mdatas) { -         if(Mdatas! =NULL) { $LOGUTILS.D ("size=>" +mdatas.size ()); $         } -          This. Mdatas =Mdatas; - notifydatasetchanged (); the     } - Wuyi     /** the * Load More Wu      * @paramMdatas -      */ About      Public voidLoadmore (list<t>Mdatas) { $         if(Mdatas = =NULL) { -              This. Mdatas =Mdatas; -}Else { -              This. Mdatas.addall (Mdatas); A         } +  the notifydatasetchanged (); -     } $  the     /** the * Removal the      * @paramDate -      */ in      Public voidRemove (T date) { the         if(Mdatas! =NULL) { the mdatas.remove (date); About notifydatasetchanged (); the         } the     } +  -     /** the * Removal the      * @paramposition the      */ -      Public voidRemoveintposition) { -         if(Mdatas! =NULL&& mdatas.size () >position) { the Mdatas.remove (position); the notifydatasetchanged (); the         } the     } -  the @Override the      Public intGetCount () { the         returnMdatas = =NULL? 0: Mdatas.size ();94     } the  the @Override the      PublicObject GetItem (intposition) {98         returnMdatas = =NULL?NULL: Mdatas.get (position); About     } - 101 @Override102      Public LongGetitemid (intposition) {103         returnposition;104     } the 106 @Override107      PublicView GetView (intposition, View Convertview, ViewGroup parent) {108         returnCreateviewfromresource (position, convertview, parent);109     } the 111     protectedView Createviewfromresource (intposition, View Convertview, the ViewGroup Parent) {113         //TODO auto-generated Method Stub the         return NULL; the     } the 117}

baseadapter<t> rewrite Createviewfromresource Implement interface, refresh, load, remove

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.