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