Android API Chinese ListView

Source: Internet
Author: User

Android API Chinese ListView

Body

I. Structure

    Public class RatingBar extends AbsSeekBar

 

Java. lang. Object

Android. view. View

Android. view. ViewGroup

Android. widget. AdapterView

Android. widget. AbsListView

Android. widget. ListView

 

Direct subclass

ExpandableListView (two-level list view viewed using the vertical scroll bar)

 

Ii. Overview

    

List View viewed through the vertical scroll bar. The content in ListAdapter is associated with this view. See List View tutorial.

 

Iii. Internal class

 

Class ListView. FixedViewInfo

Indicates a fixed view in the list, such as the header at the top and footer at the bottom.

 

Iv. XML attributes

 

Attribute name

Description

Android: choiceMode

Specifies the selection mode used by the ListView. The list mode is not selected by default.

The attribute value must be set to one of the following constants: none; the value is 0, indicating no selection mode;

SingleChoice, with a value of 1, indicates that up to one item can be selected;

MultipleChoice. The value is 2, indicating that multiple items can be selected.

See the global attribute resource symbol choiceMode.

Android: divider

Specifies that List items are separated by a certain image or color. You can use @ [+] [package:] type: name or? [Package:] [type:] name (topic attribute) to point to an existing resource. You can also use # rgb, # argb, # rrggbb or # aarrggbb format to indicate a color.

See the global attribute resource symbol divider.

Android: dividerHeight

The height of the separator. If the height is not specified, the inherent height of this separator is used. It must be a floating point in units, such as 14.5sp. Available units such as px (pixel), dp (density-independent pixels irrelevant to the density ), sp (scaled pixels based on preferred font size is a fixed proportion of pixels based on the font size), in (inches), mm (millimeters ).

You can use @ [package:] type: name

Or? The format of [package:] [type:] name (topic attribute) directs to a resource that contains this type of value.

See the global attribute resource symbol dividerHeight.

Android: entries

Reference an array that will be used in this ListView. If the array is fixed, using this attribute is easier than writing in a program.

It must start with @ [+] [package:] type: name or? [Package:] [type:] name to point to a resource.

See the global attribute resource symbol entries.

Android: footerDividersEnabled

When set to flase, this ListView will not draw a separator before the footer view. The default value of this attribute is true.

The property value must be set to true or false.

You can use @ [package:] type: name

Or? The format of [package:] [type:] name (topic attribute) directs to a resource that contains this type of value.

See the global attribute resource symbol footerDividersEnabled.

Android: headerDividersEnabled

When set to flase, this ListView will not draw a separator behind the header view. The default value of this attribute is true.

The property value must be set to true or false.

You can use @ [package:] type: name

Or? The format of [package:] [type:] name (topic attribute) directs to a resource that contains this type of value.

See the global attribute resource symbol headerDividersEnabled.

5. Constants

 

Int CHOICE_MODE_MULTIPLE

(Constant Value: 2) The list allows you to select multiple

Int CHOICE_MODE_NONE

(Constant Value: 0) normal list, does not specify the selection mode

Int CHOICE_MODE_SINGLE

(Constant Value: 1) The list can only select one


Vi. Public Methods

 

Public void addFooterView (View v)

Add a view fixed to the bottom of the list. If this method is called more than once, the added views are arranged in the order they are added. You can focus on the added view.

Note: This method is called before setAdapter is called. In this way, you can click the cursor to collapse the ListView with header view and footer view.

Parameters

View to be added

 

Public void addFooterView (View v, Object data, boolean isSelectable)

Add a view fixed to the bottom of the list. If this method is called more than once, the added views are arranged in the order they are added. You can focus on the added view.

Note: This method is called before setAdapter is called. In this way, you can click the cursor to collapse the ListView with header view and footer view.

Parameters

View to be added

Data associated with this view

If isSelectable is set to true, footer view can be selected.

 

Public void addHeaderView (View v)

Add a view fixed to the top of the list. If this method is called more than once, the added views are arranged in the order they are added. You can focus on the added view.

Note: This method is called before setAdapter is called. In this way, you can click the cursor to collapse the ListView with header view and footer view.

Parameters

View to be added

 

Public void addHeaderView (View v, Object data, boolean isSelectable)

Add a view fixed to the top of the list. If this method is called more than once, the added views are arranged in the order they are added. You can focus on the added view.

Note: This method is called before setAdapter is called. In this way, you can click the cursor to collapse the ListView with header view and footer view.

Parameters

View to be added

Data associated with this view

IsSelectable indicates whether the header view is optional.

 

Public void clearChoices ()

Cancel any previous selections

 

Public boolean dispatchKeyEvent (KeyEvent event)

Assign a key event to the next view based on the order in which the focus can be obtained (from the top of the view tree to the current view with the focus obtained. If the view has focus, the event is assigned to itself. Otherwise, it will be assigned to the next node in order. This method simultaneously triggers all button listeners.

Parameters

Event dispatched

Return

If the event is processed, true is returned; otherwise, false is returned.

 

Public boolean dispatchPopulateAccessibilityEvent (AccessibilityEvent event)

Assign a secondary event when the Child Project of the view is built.

Parameters

Event

Return

Returns true if all events are completed.

 

Public ListAdapter getAdapter ()

Returns the current ListView adapter. The returned adapter cannot be the same as the parameter passed to setAdapter (ListAdapter), but it can be WrapperListAdapter.

Return

The current adapter used to display data in ListView

See

SetAdapter (ListAdapter)

 

Public long [] getCheckItemIds ()

This method is out of date. UsegetCheckedItemIds().

Returns the index set of the selected project. It is valid only when the selection mode is not set to CHOICE_MODE_NONE.

 

Public long [] getCheckedItemIds ()

Returns the index set of the selected project. The result is valid only when the selection mode is not set to CHOICE_MODE_NONE and the adapter has a stable ID (hasStableIds () = true.

Return

A new array containing each selected index (id) in the list)

 

Public int getCheckedItemPosition ()

Returns the selected project. The result is valid only when the selection mode is set to CHOICE_MODE_SINGLE.

Return

Returns the index of the selected project. If no project is selected, INVALID_POSITION is returned.

See

SetChoiceMode (int)

 

Public SparseBooleanArray getCheckedItemPositions ()

Returns the selected project set. The result is valid only when the selection mode is not set to CHOICE_MODE_NONE.

Return

The value of the type is SparseBooleanArray. If the project represented by each index is selected, true is returned. If the selection mode is set to CHOICE_MODE_NONE, null is returned.

 

Public int getChoiceMode ()

Return

Returns the current selection mode.

See

SetChoiceMode (int)

 

Public Drawable getDivider ()

Return

Returns the graph that is used as a separator between the elements in the current painting list.

 

Public int getDividerHeight ()

Return

Returns the delimiter height.

 

Public int getFooterViewsCount ()

Return

The number of footer views in the list. The default value is 0.

 

Public int getHeaderViewsCount ()

Return

Number of header views in the list. The default value is 0.

 

Public boolean getItemsCanFocus ()

Return

Can a view generated by ListAdapter contain a project that can gain focus?

 

Public int getMaxScrollAmount ()

Return

The maximum amount a list view will scroll in response to an arrow event.

The maximum value that the List View can scroll to when an arrow event is returned. (Note: If the translation is to be improved, you may need to carefully check the source Code to understand its meaning. You can also use Google Code to search for the relevant Code)

 

Public boolean isItemChecked (int position)

For a project specified by position, the system returns whether the project is selected. The result is valid only when the selection mode is set to CHOICE_MODE_SINGLE or CHOICE_MODE_MULTIPLE.

Parameters

Position: the items in the selected status to be returned.

Return

Returns the selected project status. If the selected mode is invalid, false is returned.

 

Public boolean onKeyDown (int keyCode, KeyEvent event)

Default Implementation of KeyEvent. Callback. onKeyMultiple (): If the view is activated and can be clicked, click this view when KEYCODE_DPAD_CENTER and KEYCODE_ENTER appear.

Parameters

KeyCode indicates the key code for pressing a key. See KeyEvent

Event defines the key event object of a key action

Return

If the event is successfully processed, true is returned. If you want the next receiver to process the event, false is returned.

 

Public boolean onKeyMultiple (int keyCode, int repeatCount, KeyEvent event)

Default Implementation of KeyEvent. Callback. onKeyMultiple (): always return false (not to handle this event ).

Parameters

KeyCode indicates the key code for pressing a key. See KeyEvent

RepeatedCount

Event defines the key event object of a key action

Return

If the event is successfully processed, true is returned. If you want the next receiver to process the event, false is returned.

 

Public boolean onKeyUp (int keyCode, KeyEvent event)

Default Implementation of KeyEvent. Callback. onKeyMultiple (): When KEYCODE_DPAD_CENTER and KEYCODE_ENTER are displayed, click this view.

Parameters

KeyCode indicates the key code for pressing a key. See KeyEvent

Event defines the key event object of a key action

Return

If the event is successfully processed, true is returned. If you want the next receiver to process the event, false is returned.

 

Public void onRestoreInstanceState (Parcelable state)

Recreate and display a view, which has the internal status saved by onSaveInstanceState. If the state is null, this method is not called.

Parameters

Status of onSaveInstanceState () saved before state

 

Public Parcelable onSaveInstanceState ()

Save the internal status of the view to create a new instance in the same status. The saved status only contains non-persistent or reusable information. For example, it is never possible to save your current location on the screen, because when a new instance is placed in the view hierarchy, the location will be recalculated.

Some States that can be saved: The current cursor position in the text view (but usually not the text itself, because the text is saved in the content provider or other persistent storage bodies; the selected items in the list view.

Return

Returns an interface method object that contains the current dynamic state of the view. If nothing is saved, null is returned. By default, null is returned.

 

Public boolean onTouchEvent (MotionEvent ev)

This method is used to process touch screen action events.

Parameters

Ev Action event

Return

If the event is successfully processed, true is returned; otherwise, false is returned.

 

Public boolean initialize mitemclick (View view, int position, long id)

Call the defined OnItemClickListener.

Parameters

View AdapterView

Position View index in the adapter

The row id of the project to which the id is clicked

Return

If the defined OnItemClickListener is successfully called, true is returned; otherwise, false is returned.

 

Public boolean removeFooterView (View v)

Delete a previously added footer view.

Parameters

V view to be deleted

Return

If the view is successfully deleted, true is returned. If the view is not a footer view, false is returned.

 

Public boolean removeHeaderView (View v)

Delete a previously added header view.

Parameters

V view to be deleted

Return

If the view is successfully deleted, true is returned. If the view is not a header view, false is returned.

Public boolean requestChildRectangleOnScreen (View child, Rect rect, boolean immediate)

This method is called when a subitem in A group needs to be located in a rectangle range on the screen.

Reload the ViewGroup of this method to confirm the following:

· Sub-projects will be the immediate sub-items in the group

· The rectangle will be in the coordinate system of the subitem

The ViewGroup that overload this method must ensure the following:

· If the rectangle is visible, nothing will change

· To make the rectangle area visible, the view can be displayed in a scroll manner.

Parameters

Child sub-project that sends the request

Rect the rectangle in the sub-project coordinate system, that is, the position of the sub-project to be located on the screen

If immediate is set to true, animation and slow-release moving scroll bars are prohibited.

Return

Whether to accept the request for this scrolling Group

 

Public void setAdapter (ListAdapter adapter)

Set the data behind the ListView. Based on the features currently used by ListView, the adapter may be collapsed by WrapperListAdapter. For example, adding a header and/or footer will collapse the adapter.

Parameters

The adapter is responsible for maintaining the data behind the list and generating views to display projects in the data.

See

GetAdapter ()

 

Public void setCacheColorHint (int color)

When the value of color is not 0, the color indicated by this value will prompt the user, and the list is being drawn on a monochrome opaque background.

Parameters

Color background color

 

Public void setChoiceMode (int choiceMode)

Set the List selection mode. By default, no mode is selected for the List (that is, the value is CHOICE_MODE_NONE ).

Parameters

The choiceMode value can be one of CHOICE_MODE_NONE, CHOICE_MODE_NONE, and CHOICE_MODE_NONE.

 

Public void setDivider (Drawable divider)

Set the drawing between each project in the list. If the image does not have a set height, you must call setDividerHeight (int) at the same time ).

Parameters

Divider: The image that will be used as a separator

 

Public void setDividerHeight (int height)

Set the height of the delimiter (between projects in the list. Calling this method will overwrite the height set by setDivider (Drawable.

Parameters

The new height of the height separator, in pixels.

 

Public void setFooterDividersEnabled (boolean footerDividersEnabled)

The settings can or cannot be used to draw separators on the footer view.

Parameters

Set headerDividersEnabled to true, indicating that the image can be painted. Set it to false.

See

SetHeaderDividerEnabled (boolean)

AddFooterView (android. view. View)

 

Public void setHeaderDividersEnabled (boolean headerDividersEnabled)

The settings can or cannot be used as separators for the header view.

Parameters

Set headerDividersEnabled to true, indicating that the image can be painted. Set it to false.

See

SetFooterDividerEnabled (boolean)

AddHeaderView (android. view. View)

 

Public void setItemChecked (int position, boolean value)

Set the selection Status of the project specified by position. This setting is valid only when the selection mode is CHOICE_MODE_SINGLE or CHOICE_MODE_MULTIPLE.

Parameters

Index of the project whose position needs to change the selection status

New Selection status of value

 

Public void setItemsCanFocus (boolean itemsCanFocus)

It indicates that the view created by ListAdapter can contain items that can obtain the focus.

Parameters

ItemsCanFocus: if the project obtains the focus, set it to true; otherwise, set it to false.

 

Public void setSelection (int position)

Select the project specified by position. If it is in touch mode, the specified project will not be selected, but the location changes the same. If the position value is less than 0, items whose position is 0 will be selected.

Parameters

Position: Index of the project to be selected (starting from 0)

 

Public void setSelectionAfterHeaderView ()

Select the first list item in the header view.

 

Public void setSelectionFromTop (int position, int y)

Select the project specified by position and place the option at the position y pixel from the top of the ListView (if it is in touch mode, the specified project will not be selected, but the position will change the same ).

Parameters

Position: Index of the project to be selected (starting from 0)

Y distance from the top of ListView (including gap)

 

VII. Protected Methods

 

Protected boolean canAnimate ()

Indicates whether this view group can dynamically adjust its subitems after being laid out for the first time.

Return

If yes, true is used. Otherwise, false is used.

 

Protected void dispatchDraw (Canvas canvas)

Call this method to plot the subview. It can be overwritten by the category class to gain control before its subitem is drawn.

Parameters

Canvas: canvas used to draw a View ?)

 

Protected View findViewTraversal (int id)

Parameters

Id of the View to be queried

Return Value

View with this id. null if not found

 

Protected View findViewWithTagTraversal (Object tag)

Parameters

Tag: The tag of the View

Return Value

View with this label. null if not found

 

Protected void layoutChildren ()

Subclass must override this method to layout its subitem.

 

Protected void onFinishInflate ()

This is the last step to import a View and all its sub-items. Even if the subclass overrides onFinishInflate, you must ensure that a supermethod is called so that the method will be called.

 

Protected void onFocusChanged (boolean gainFocus, int direction, Rect previouslyFocusedRect)

Called when the View focus changes. During rewriting, make sure that the superclass is called directly, so that the method of getting the focus is standard.

Parameters

If the View has focus, the value is True; otherwise, the value is False.

Direction when requestFocus () is called, the direction focus is moved. The value can be FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT or FOCUS_RIGHT. When the default conditions are used, direction is not always available.

Previuslyfocusedrect is the rectangle formed by the coordinate system of the View in focus. If available, this will be passed as accurate information (indicating where the focus comes from and where it comes from); otherwise, null will be passed.

 

Protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)

View calls this method to determine the size of itself and the Content contained. This method is called by measure (int, int) and must be overwritten by the quilt class to get the exact size of the Content contained.

Note: When you override this method, you must call setMeasureDimension (int, int) to save the View size. If this is not done, an IllegalStateException (invalid state error) thrown by measure (int, int) is thrown ). The onMeasure (int, int) class can be called.

The method for determining the size of the base class is determined by default based on the background size, unless MeasureSepc allows a larger height or width. The subclass must override onMeasure (int, int) to get a more accurate measurement of its content size.

If this method is overwritten, its subclass must ensure that its height and width must at least reach the minimum value specified by View (which can be obtained through getSuggestedMinimumHeight () and getSuggestedMinimumWidth ).

Parameters

WidthMeaureSpec is subject to horizontal space requirements under the influence of the size of the previous layer. See View. MeasureSpec.

HeightMeasureSpec is subject to the vertical space requirements under the influence of the size of the previous layer. See View. MeasureSpec.

 

Protected void onSizeChanged (int w, int h, int oldw, int oldh)

This method is called when the VIew Size changes. If the VIew is just added, the previous value is 0.

Parameters

Current width of w View

H View current height

The size of the oldw View changes the previous width.

The size of the oldh View changes the previous height.

 

 

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.