During development, we often encounter complicated layout of the GridView/ListView. The re-implementation of BaseAdapter not only helps us achieve the layout we want, in addition, when binding a large amount of data, it does not feel stuck. Remember to use a ListView to directly bind the contact Cursor in the mobile phone (more than one hundred people), sliding will feel stuck. I decided to write a Demo today because the project may achieve this effect:Bind four ImageButton to a GridView. Some buttons are unavailable under certain circumstances, that is, Enable = false. Different buttons must have different click events..
First, add a flag boolean bl to control the Enable status of the button. Second, add View. onClickListener to the List.
1. MyAdapter. java inherits from BaseAdapter
Public ClassMyAdapterExtendsBaseAdapter {
PrivateContext context;
PrivateList<Map<String, Object>List;
PrivateLayoutInflater mInflater;
PublicMyAdapter (Context context, List<Map<String, Object>List ){
This. Context=Context;
This. List=List;
MInflater=LayoutInflater. from (This. Context );
}
Public IntGetCount (){
//TODO Auto-generated method stub
If(List! =Null)
ReturnList. size ();
Else
Return 0;
}
PublicObject getItem (IntPosition ){
//TODO Auto-generated method stub
If(List! =Null)
ReturnList. get (position );
Else
Return Null;
}
Public LongGetItemId (IntPosition ){
//TODO Auto-generated method stub
ReturnPosition;
}
@ SuppressWarnings ("Unused")
PublicView getView (IntPosition, View convertView, ViewGroup parent ){
//TODO Auto-generated method stub
ViewHolder holder=Null;
If(Holder=Null){
Holder=NewViewHolder ();
ConvertView=MInflater. inflate (R. layout. gridview_item,Null);
Holder. ib=(ImageButton) convertView. findViewById (R. id. ib );
ConvertView. setTag (holder );
}Else{
Holder=(ViewHolder) convertView. getTag ();
}
//Bind a click event
Holder. ib. setOnClickListener (OnClickListener) list. get (position). get ("Listen"));
//Enable with flag control button
If(Boolean. parseBoolean (list. get (position). get ("Bl"). ToString ()))
Holder. ib. setEnabled (True);
Else
H