Advanced Controls "Android 5"-scrolling view, List view [ListView, Simpleadapter class]

Source: Internet
Author: User

Scrolling view

<scrollview

Android:layout_width="Fill_parent"

android:layout_height="Fill_parent">

</ScrollView>

Scrolling attempts to refer to a special container that can hold more components than the width of the screen, and then use a drag-and-drop approach

Show all components in ScrollView

Note: There can only be one component in a scrolling view

List View "ListView, Simpleadapter class"

1. TheListView control Features: Each list item has a single row, and each row has the same layout.

2. Use the Simpleadapter class to set up a list view

The primary function of the Simpleadapter class is to convert the data from the list collection to data that the ListView can support.

New simpleadapter (Context object "this", List of data, list item layout resource file, 

Key an array the group "New string[]{" label name "}", the index value of all controls in the list item "new int[]{r.id. Control ID")

Method

Describe

Public Simpleadapter ( context context,

list<? Extends Map<string,?>>

int resource, string[] from, int[] to)

Create a Simpleadapter object that needs to pass in the context object, the encapsulated list collection, the layout file ID to be used, the key to display (corresponding map), the ID of the component

public int GetCount ()

Get the number of saved collections

Public Object getItem (int position)

Gets the object at the specified position

public long getitemid (int position)

Gets the ID of the specified Location object

public void notifydatasetchanged ()

Notification updates show ListView when list items are changed

List item display template--res/layout/data_list.xml

ListView Event

method

TD valign= "Top" width= "284" >

description

public Void Setonitemselectedlistener (

adapterview.onitemselectedlistener listener)

When selected, triggers

public Void Setonitemclicklistener (

P align= "center" >adapterview.onitemclicklistener listener)

option when clicked to trigger

public Void Setonitemlonglistener (

Adapterview.onitemlonglistener listener)

option long trigger on time

1ListView lv=(ListView) Findviewbyid (R.id.listview);2List<map<string,object>> list=NewArraylist<map<string,object>>();3     //getting data from an array resource4String[] Data=getresources (). Getstringarray (R.array.haha);5      for(inti=0;i<data.length;i++){6Map<string,object> map=NewHashmap<string,object>();7Map.put ("img", r.drawable.b);8Map.put ("TXT", Data[i]);9 list.add (map);Ten     } One //parameter list: Context object, list data, list item layout resource file, key an array group, list item index value for all controls ASimpleadapter adapter=NewSimpleadapter ( This, List,r.layout.data_list,NewString[]{"img", "TXT"},New int[]{R.ID.DATAIMG,R.ID.DATATV}]; - Lv.setadapter (adapter); -  the //to set a click event for a ListView -Lv.setonitemclicklistener (NewOnitemclicklistener () { -             /**The ListView option is triggered when clicked - * ADP gets Adapterview object + * View gets Adapterview's parent component - * Position get adapter operation position + * ID Gets the number of the row where the ListView is located A              */ at          Public voidOnitemclick (adapterview<?> ADP, view view,intPositionLongID) { -Object obj=adp.getitematposition (position); -Map<string, object> objs= (map<string, object>) obj; -String str= (String) objs.get ("TXT"); -Toast.maketext (Listview. This, str, 1000). Show (); -         } in     }); -     
the use of Simpleadapter and list events-part of the Code

Advanced Controls Android 5-scrolling view, List view [ListView, Simpleadapter class]

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.