Use of adapter adapter in Android

Source: Internet
Author: User

    The most commonly used adapters in Android are adapter three kinds: 1.ArrayAdapter 2.SimpleAdapter 3.BaseAdpter, here we use the code in conjunction with the text to understand the way.

  You first need to set up three button buttons in the start layout activity_main.xml file and set the click events separately and combine with the mainactivity

  

One: Arrayadapter: Easy-to-use adapter, typically used to wrap multiple values of an array or list collection into multiple list items.

1. The first step in declaring Arrayadapter: Create a Activity_array_adapter.xml, create a ListView control

2. Declaring the control in Arrayadapteractivity and building the adapter

    Here is how to prepare the Data section: array data and collection data two

    Here is the second parameter in adapter () when building the adapter, Textviewresouceid, which represents a Arrayadapter list item component

Two: Simpleadapter:

Create activity and declare the display interface Activity_simple_adapter

    

    

    

Declaring a Activity_simple_adapter_item.xml file in build adapter

    

    

Three: Baseadapter

Write to an entity class user class

    

Create a Userlistadapter class

    

    

    

Returns the Uiactivity_base_adapter_item.xml layout file in the Userlistadapter,getview method, where the method 1,getcount () and Method 4,getview () are important

Here are the five TextView written in Baseadapter written separately.

    

Statement baseadapteractivity

    

Create a layout UI interface Activity_base_adapter

    

This part is my own practice adapter adapter when the set of code, but only the use of the ListView, but not listed in the use of the GridView, but the difference is not particularly large

    

  

 

Use of adapter adapter in Android

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.