Android Adapter details

Source: Internet
Author: User

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

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.