Android Control class 3rd--adapterview

Source: Internet
Author: User

Adapterview The greatest feature of this type of control, in the vast majority of cases, their data is provided by adapter subclasses (sometimes the displayed data can be set directly on the entries property of the control).

Call Adapterview's Setadapter (Adapter) to associate the control with the data.

I. Overview

Adapterview is an abstract class, she inherits the Groupview, so it is a container class. It has three subclasses: Abslistview, Absspinner, Adapterviewanimator, and these three subclasses are also abstract classes. The corresponding adapter is an interface that contains two interfaces: ListAdapter, Spinneradapter. Adapterviewanimator subclasses are typically used to slide the previous, next control.

When adding data to the Abslistview subclass, use Setadapter (ListAdapter) and Setadapter (Spinneradapter) when adding data to the Absspinner subclass When adding data to the Adapterviewanimator subclass, call Setadapter (Adapter), that is, when providing data for the Adapterviewanimator subclass, you can use ListAdapter, You can also use Spinneradapter. In fact, in the actual use, there will not be too much difference. Because in practice, baseadapter and its subclasses are usually used (Arrayadapter, Simpleadapter, CursorAdapter, Resourcecursoradapter, Simplecursoradapter), while the Baseadapter implements the ListAdapter and Spinneradapter two interfaces.

It is important to note that the sub-class Expandablelistview of the ListView. Under normal circumstances, this class should call Setadapter (ListAdapter) to correlate the data. However, Setadapter (ListAdapter) cannot meet the requirements according to the special requirements of expandablelistview rendering data, so this method throws an exception; This class provides Setadapter (Expandablelistadapter), which is used to correlate data. Expandablelistadapter does not inherit adapter or ListAdapter, and it does not inherit any interfaces. Its implementation classes include Baseexpandablelistadapter, Simpleexpandablelistadapter, Cursortreeadapter, Resourcecursortreeadapter, Simplecursortreeadapter, of which, 1th, 2, 5 are more commonly used.

Second, the common control

1,Abslistview, inherit from Adapterview, need to use Setadapter (listadapter) Association data

Android:choicemode, set Abslistview selection behavior, single/Multiple selection (None/singlechoice/multiplechoice/multiplechoicemodal)

Android:drawselectorontop (Setdrawselectorontop (Boolean)), True, the selected item is displayed to the top

Android:listselector (setselector (int)), which specifies the drawable drawn on the selected list item

2,ListView, inherit from Abslistview, need to use Setadapter (listadapter) Association data

You can use Activity+listview (add your own ListView control)

You can also use listactivity directly, this activity comes with a ListView

Android:divider, the delimiter for a list item, either a color or a drawable

Android:dividerheight, delimiter height

Android:entries, specifying an array that indicates the data to display

3,GridView, inherit from Abslistview, need to use Setadapter (listadapter) Association data

The GridView is similar to a ListView. The difference is that the ListView displays only one column, and the GridView can display multiple columns. If the GridView has only one column set, it is the same as the ListView.

You can set the number of columns to display by Android:numcolumns (setnumcolumns (int)).

  

4,Autocompletetextview, inherit from TextView, need to use Setadapter (listadapter) Association data

Without inheriting Adapterview and its subclasses, it also uses Setadapter to provide data for it, so put it here.

The declaration of its Setadapter method is as follows: Public <T extends ListAdapter & filterable> void Setadapter (t adapter) {...}

5,Multiautocompletetextview, inherit from Autocompletetextview, need to use Setadapter (listadapter) Association data

Basically similar to Autocompletetextview. Just Multiautocompletetextview can be entered multiple times and matches the information in adapter multiple times. Two times the input is set with Settokenizer (Multiautocompletetextview.tokenizer). And Multiautocompletetextview provides a tokenizer--commatokenizer. This tokenizer represents a comma. The notation is Settokenizer (new Multiautocompletetextview.commatokenizer ()).

6,Spinner, inherit from Absspinner, need to use Setadapter (spinneradapter) Association data

Spinner is a list box that provides the user's choice, similar to a drop-down list box, except that the rendering option is not a drop-down list, but rather pops up a list box.

7,Gallery, inherited from Absspinner, need to use Setadapter (spinneradapter) Association data , has not been recommended to use

Spinner is a vertical, gallery is a horizontal one.

Spinner provides user selection, gallery is typically used for viewing, and you can swipe to view the previous and next list items.

It is deprecated to use gallery, instead of using Horizontalscrollview and Viewpager.

8,Adapterviewanimator, inherit from Adapterview, need to use Setadapter (Adapter) Association data

Only one view can be displayed at a time (view is provided by the Adapter.getview () method)

Show previous and Next view through Showprevious () and Shownext ()

Android:animatefirstview property that shows whether an animation is used when the first view is displayed

Android:inanimator,android:outanimator properties, animations used when displaying and hiding

Android:loopviews property, whether to restart the loop from the first view after the loop has ended

8,Adapterviewflipper, inherit from Adapterviewanimator, need to use Setadapter (Adapter) Association data

The Android:autostart Property/startflipping () method starts AutoPlay, and the stopflipping () method stops AutoPlay.

The Android:flipinterval property/setflipinterval (int) method sets the event interval for AutoPlay.

9,StackView, inherit from Adapterviewanimator, need to use Setadapter (Adapter) Association data

Unlike Adapterviewfilpper, StackView displays multiple list items in a stacked manner

Drag the view at the top of the StackView to display the next view, and drag the previous view into the StackView, then the view will be displayed.

You can also display the previous, next, Showprevious, Shownext

10,Expandablelistview, inherit from ListView, need to use Setadapter (expandablelistadapter) Association data

It is a multi-level listview that has both groups and members within the group.

The Android:childdivider property, the separator bar between the sub-list items within the group, the Android:divider property, and the separator bar between the groups.

The Android:childindicator property, the Drawable object next to the child list item, android:groupindicator the Drawable object next to the group list item.

There are two setadapter, one of which is inherited from the Setadapter (ListAdapter) of the ListView, and in order to prevent this method from being used, this method throws an exception.

Common Expandablelistadapter subclasses include: Baseexpandablelistadapter, Simpleexpandablelistadapter, Simplecursortreeadapter

If you use Baseexpandablelistadapter, you need to implement its methods. The more important methods are:

      • GetGroupCount
      • Getgroupview
      • Getchildrencount
      • Getchildview

  

III. adapter and its sub-categories

1,Arrayadapter, inherit from Baseadapter

New A arrayadapter, which typically calls a constructor of three arguments:

      • Context
      • ResourceID for rendering a single list item
      • The list/array object is passed as a parameter to the constructor.

2,Simpleadapter, inherit from Baseadapter

Like Arrayadapter, New is a simpleadapter, but the parameters are slightly more complex. Altogether 5 parameters:

      • Context
      • A list< for storing data;? Extends map<string,?>>
      • ResourceID for rendering a single list item
      • String[], an array of strings corresponding to the string in map<string,?> in the 2nd argument
      • Int[], which represents the control ID, corresponds to the third parameter and the fourth parameter. The third parameter can be a complex combination of controls, each item in an int array, corresponding to the ID of a control in the third parameter, and a string field in the 4th argument. Represents the data for the string field in the 2nd parameter, displayed on the control corresponding to the 3rd parameter.

3,baseadapter, realized the ListAdapter and Spinneradapter

Baseadapter is an abstract class that needs to implement its methods.

Most importantly, you need to implement its GetView method: public view GetView (int position, view Convertview, ViewGroup parent)

In the parameters of the GetView method, the most notable is the 2nd parameter, Convertview. If you need to display more items, one screen cannot be displayed, the scroll bar is displayed. This parameter represents the view that was just hidden when the scroll bar was scrolled. This view is hidden, and we can use this view to present the view that we just showed, instead of recreating a view. This greatly reduces the consumption of memory and time.

4,Baseexpandablelistadapter

It is an abstract method, and its subclasses are more commonly used including: Simpleexpandablelistadapter, Simplecursortreeadapter

If you use Baseexpandablelistadapter in your code, the more important ways to implement it are:

      • public int Getchildrencount (int groupposition)
      • Public View getchildview (int groupposition, int childposition, Boolean islastchild, View Convertview, ViewGroup parent)
      • public int GetGroupCount ()
      • Public View getgroupview (int groupposition, Boolean isexpanded, View Convertview, ViewGroup parent)

Android Control class 3rd--adapterview

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.