Android Adapter is a bridge class that binds data to the UI. The Adapter is responsible for creating and displaying sub-views for each project and providing access to lower-layer data. The abstract class of the Adapter View must be extended for UI controls that support Adapter binding. It is possible to create your own controls inherited from AdapterView and create an Adapter class to bind them.
The Android system provides two ready-made adapters for us to use.
1. ArrayAdapter: it is a common class bound to a group of objects. By default, ArrayAdapter binds the toString value of each object to the pre-defined TextView space in layout. Constructor allows you to use more complex Layout or override the getView method to extend the class and use the substitute of TextView.
2. SimpleCursorAdapter: binds the View to the cursor returned by the Content Provider query. Specify an XML layout definition, and then bind the values of each column of the dataset to a View in layout.
Write your own Adapter class to implement more complex UI interfaces and Data Binding
Public class MyAdapter extends SimpleAdapter {
Private LayoutInflater mInflater;
Private Context context;
Private List <Map <String, Object> list;
Private int resource;
Private String [] tags;
Private int [] ids;
Public MyAdapter (Context context, List <Map <String, Object> items, int resource,
String [] tags, int [] ids ){
Super (context, items, resource, tags, ids );
This. mInflater = LayoutInflater. from (context );
This. context = context;
This. list = items;
This. resource = resource;
This. tags = tags;
This. ids = ids;
}
Public int getCount (){
Return list. size ();
}
Public Object getItem (int position ){
Return list. get (position );
}
Public long getItemId (int position ){
Return position;
}
Public View getView (final int position, View convertView, ViewGroup parent ){
ConvertView = super. getView (position, convertView, parent );
If (convertView = null ){
Toast. makeText (context, "this is null", 2000). show ();
} Else {
}
ImageView more = (ImageView) convertView. findViewById (R. id. iv_more );
More. setOnClickListener (new View. OnClickListener (){
Public void onClick (View arg0 ){
Intent intent = new Intent (context, VehicleInfoActivity. class );
Intent. putExtra ("vehicleID", VehicleListActivity. idList. get (position ));
Intent. putExtra ("CameraID", "0 ");
Toast. makeText (context, "sssssss", 2000). show ();
Context. startActivity (intent );
}
});
Return convertView;
}
}
Author: gps dream