Android API Chinese (--adapterview)

Source: Internet
Author: User

Objective

The content of this chapter is Android.widget.AdapterView, version of Android 2.3 R1, translated from "Cnmahj", Welcome to visit his blog: http://android.toolib.net/blog/, thank you Again " Cnmahj "! You are welcome to participate in the Chinese translation of Android API, contact me [email protected].

Statement

Welcome reprint, but please keep the original source of the article:)

Blog Park: http://www.cnblogs.com/

Android Chinese translation group: http://code.taobao.org/project/view/404/

Body

First, the structure

Public abstract class Adapterview<t extends adapter> extends ViewGroup

Java.lang.Object

Android.view.View

Android.view.ViewGroup

Android.widget.adapterview<t extends Android.widget.adapter>

Direct sub-class

Abslistview, Absspinner

Indirect sub-class

Expandablelistview, Gallery, GridView, ListView, Spinner

Ii. Overview

Adapterview is the Adapter view class that is determined by the content.

See ListView , GridView ,, Spinner and Gallery other common subclasses.

Three, constant

public static final int invalid_position

Represents an invalid location. Valid values range from 0 to the current number of adapter items minus 1.

Constant Value:-1 (0xFFFFFFFF)

public static final Long invalid_row_id

Represents an empty or invalid row ID.

Constant value: -9223372036854775808 (0x8000000000000000)

public static final int Item_view_type_header_or_footer

getItemViewType(int)The return value of the function is called when the item is the list header or footer of the list.

Constant Value:-2 (0xFFFFFFFE)

public static final int Item_view_type_ignore

The getItemViewType(int) return value of the function is called when the adapter prohibits the view reuse of the bar item.

Constant Value:-1 (0xFFFFFFFF)

Four, the constructor function

Public Adapterview (Context context)

constructor function

Public Adapterview (context context, AttributeSet attrs)

constructor function

Public Adapterview (context context, AttributeSet attrs, int defstyle)

constructor function

V. Public methods

public void AddView (View child)

The class does not support this method if the call throws a Unsupportedoperationexception exception.

Parameters

Child ignores

Abnormal

Unsupportedoperationexception when the method is called

public void AddView (View Child, int index)

The class does not support this method if the call throws a Unsupportedoperationexception exception.

Parameters

Child ignored.

Index is ignored.

Thrown

Unsupportedoperationexception when the method is called

public void AddView (View child, int index, viewgroup.layoutparams params)

The class does not support this method if the call throws a Unsupportedoperationexception exception.

Parameters

Child ignored.

Index is ignored.

params is ignored.

Thrown

Unsupportedoperationexception when the method is called

public void AddView (View child, Viewgroup.layoutparams params)

The class does not support this method if the call throws a Unsupportedoperationexception exception.

Parameters

Child ignored.

params is ignored.

Thrown

Unsupportedoperationexception when the method is called

public boolean dispatchpopulateaccessibilityevent (accessibilityevent event)

The distribution AccessibilityEvent event to 该视图 the child view.

Parameters

Event events.

return value

Returns true if event distribution is complete.

Public abstract T getadapter ()

Returns the adapter currently associated with the widget.

return value

The adapter that is used to provide the view content.

public int GetCount ()

return value

The number of entries for the adapter associated with the Adapterview. (The value is the number of data entries, which may be greater than the number of views that are visible.) )

Public View Getemptyview ()

Adapterview displays a special empty view when the current adapter has no content. The empty view is used to tell the user that the Adapterview has no data.

return value

The view that is displayed when the adapter is empty.

public int getfirstvisibleposition ()

Returns the position of the first element displayed on the screen in the adapter.

return value

The location in the adapter data set.

Public Object getitematposition (int position)

Gets the data at the specified location in the list.

Parameters

Position where to get the data.

return value

The data at the specified location in the list.

Public long getitemidatposition (int position)

(Translator Note: For an analysis of this method, see here.) )

public int getlastvisibleposition ()

Returns the position in the adapter where the last element displayed on the screen is located.

return value

The location in the adapter data set.

Public final Adapterview.onitemclicklistener Getonitemclicklistener ()

return value

The callback function that executes when the entry in Adapterview is clicked, or null if no setting is set.

Public final Adapterview.onitemlongclicklistener Getonitemlongclicklistener ()

return value

Gets the listener of the callback function that executes when the entry in Adapterview is pressed, or null if not set.

Public final Adapterview.onitemselectedlistener Getonitemselectedlistener ()

public int Getpositionforview (view view)

Gets the position of the adapter item that corresponds to the view or its child view in the adapter's data.

Parameters

Views of the view adapter entry or its descendants. Called when the item must be visible in the Adapterview.

return value

The location of the view in the adapter dataset, or if the view is not in the data list or is not currently visible INVALID_POSITION .

Public Object GetSelectedItem ()

return value

The data for the currently selected entry, and null if no entry is selected.

Public long Getselecteditemid ()

return value

The corresponding ID of the currently selected entry, and the invalid_row_id is returned without a selected entry.

public int getselecteditemposition ()

Returns the position of the currently selected item in the adapter data.

return value

Returns the zero-based position (index) information, returning invalid_position when no entry is selected.

Public abstract View Getselectedview ()

return value

The view that corresponds to the currently selected item, or null if no entry is selected.

public boolean Performitemclick (view view, int position, long ID)

If Onitemclicklistener is defined, it is called.

Parameters

The view that was clicked in the view Adapterview.

The index of the position view in the adapter.

ID The line ID of the entry that was clicked.

return value

Returns true if the defined Onitemclicklistener is successfully invoked, otherwise false.

public void Removeallviews ()

The class does not support this method if the call throws a Unsupportedoperationexception exception.

Thrown

Unsupportedoperationexception when the method is called

public void Removeview (View child)

The class does not support this method if the call throws a Unsupportedoperationexception exception.

Parameters

Child ignored.

Thrown

Unsupportedoperationexception when the method is called

public void Removeviewat (int index)

The class does not support this method if the call throws a Unsupportedoperationexception exception.

Parameters

Index is ignored.

Thrown

Unsupportedoperationexception when the method is called

public abstract void Setadapter (T adapter)

Sets the adapter used to provide the data for the display for the view of the widget.

Parameters

Adapter the adapter used to create the view content.

public void Setemptyview (View emptyview)

Sets the view that is displayed when the adapter content is empty.

public void setfocusable (Boolean focusable)

Sets whether the view can get the focus. When set to False, you can ensure that the view does not receive focus in touch mode.

Parameters

When Focusable is set to True, the view can get focus.

public void Setfocusableintouchmode (Boolean focusable)

Sets whether the view can get focus in touch mode. When set to True, you can guarantee that the view can get focus.

Parameters

When Focusable is set to True, the view can be focused in touch mode.

public void Setonclicklistener (view.onclicklistener L)

Registers a callback function that executes when the view is clicked. If the view is not clickable, it will change to a clickable state.

Parameters

The callback function that runs when the event occurs.

public void Setonitemclicklistener (Adapterview.onitemclicklistener Listener)

Registers a callback function that executes when you click an entry in Adapterview.

Parameters

Listener the callback that will be invoked.

public void Setonitemlongclicklistener (Adapterview.onitemlongclicklistener Listener)

Registers a callback function that executes when long presses an entry in Adapterview.

Parameters

The callback function that runs when the listener event occurs.

public void Setonitemselectedlistener (Adapterview.onitemselectedlistener Listener)

Registers the callback function that is executed when an entry in Adapterview is checked.

Parameters

The callback function that runs when the listener event occurs.

public abstract void setselection (int position)

Sets the current selection entry. In order to support the accessibility feature, the subclass that overrides the method must first call the method of the parent class.

Parameters

Position the index (zero-based) of the selected data entry.

Vi. Methods of protection

Protected Boolean cananimate ()

Indicates whether the view group can provide an animated display for its child views after the first layout.

return value

Returns true if the child view can use the animation effect, otherwise false.

protected void dispatchrestoreinstancestate (sparsearray<parcelable> container)

Overrides to prevent the adapter-generated view from being unfrozen.

Parameters

Container holds sparsearray that have previously stored state information.

protected void dispatchsaveinstancestate (sparsearray<parcelable> container)

Override to prevent the adapter-generated view from being frozen.

Parameters

Container The Sparsearray that holds the view state.

protected void OnLayout (boolean changed, int left, int top, int. right, int bottom)

Called when the view sets the size and position of its child views. A derived class can override this method and lay out its child classes.

Parameters

Changed whether the new size and position are set for the view.

The left position relative to the parent view.

The position of top relative to the upper part of the parent view.

The right position relative to the parent view.

The position of the bottom relative to the bottom of the parent view.

Vii. Supplementary

Additional Information

This article was converted from the Android Chinese online document.

Featured Articles

Chubby ' s Blog

Android SDK Chinese Document Plan (14) Use Adapterview to bind data

Android API Chinese (--adapterview)

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.