Detailed description of the 4.UiCollection API

Source: Internet
Author: User
Tags throw exception dialpad

First, Uicollection class introduction
    • The Uicollection class has two functions: finding an object from a collection, and getting the number of components of a search condition
1.UiCollection class Description

1) Uicollection is a subclass of UIObject and can use all the APIs in UIObject
2) Uicollection represents the element entry combination

2.UiCollection function Description

1) First, according to certain conditions, the Container class interface all eligible sub-elements
2) Meet the conditions of the element again through certain conditions to finally locate the required components

3.UiCollection Usage Scenarios

1) General use of container class components as parent class
2) generally used in cases where a subclass is needed and the subclass is not positioned as a result of some of these factors
3) Get the number of a category, such as the number of contacts under the current view under the contact list

Second, find the object from the collection 1. Related API description
 Public UiObject getchildbydescription (uiselector childpattern,string text)  Public UiObject getchildbytext (uiselector childpattern,string text)  Public UiObject getchildbyinstance (uiselector childpattern,int  instance) search in the Uiselector selector criteria from the child UI element, Recursively look for all the earlier subsets that meet the criteria. Use description /text/instance criteria again to navigate from the previous search subset to the desired element
2. Parameters:

Tables

Is

Childpattern Uiselector selection criteria from a child element
Text, instance Search for elements again with description/text/instance criteria from the searched element
return value: UiObject
Throw exception: Uiobjectnotfoundexception

    • 例如:
 Public voidTestDemo1 ()throwsuiobjectnotfoundexception{//getchildbytext () [interface stuck in File Manager interface]//1. Get a collection of all components by class nameUicollection collection=NewUicollection (NewUiselector (). ClassName ("Android.widget.ListView")); //2. Delete the collection in step 1 by the class nameUiselector childpattern=NewUiselector (). ClassName ("Android.widget.TextView"); //3. Final selected music file via textString text= "Music"; UiObject Music=Collection.getchildbytext (Childpattern, text); //4. Click the Music buttonMusic.click (); //getchildbydescription () [interface stuck in dial-up interface]//1. Find all the component collections by ResourceIDUicollection collection1=NewUicollection (NewUiselector (). ResourceId ("Com.android.dialer:id/dialpad")); //2. Filtering the components in step 1 collection by class nameUiselector childpattern=NewUiselector (). ClassName ("Android.widget.ImageButton"); //3. Final positioning to the selected component via textString text= "Four"; UiObject Forth=collection1.getchildbydescription (Childpattern, text); //4. ClickForth.click (); //getchildbyinstance () [interface stuck in dial-up interface]//1. Find all the component collections by ResourceIDUicollection collection1=NewUicollection (NewUiselector (). ResourceId ("Com.android.dialer:id/dialpad")); //2. Filtering the components in step 1 collection by class nameUiselector childpattern=NewUiselector (). ClassName ("Android.widget.ImageButton"); //3. The components to be used by instance final positioning (10086 for example)UiObject child1=collection1.getchildbyinstance (childpattern, 0); UiObject child0=collection1.getchildbyinstance (Childpattern, 10); UiObject child01=collection1.getchildbyinstance (Childpattern, 10); UiObject Child8=collection1.getchildbyinstance (Childpattern, 7); UiObject Child6=collection1.getchildbyinstance (Childpattern, 5); //4. ClickChild1.click ();    Child0.click ();    Child01.click ();    Child8.click (); Child6.click ();}

Iii. getting the number of components of a search condition

1. Related API description

 Public int Getchildcount (Uiselector Childpattern) recursively finds the number of all eligible descendants collections by Uiselector find criteria

Parameters

Childpattern

Selection criteria

return value Int Eligible descendants of the collection
    • 例如:
 Public voidTestDemo2 ()throwsuiobjectnotfoundexception{//Example one: int getchildcount () [interface stuck in dial-up interface]//1. Search for the topmost component on the Uiautomatorview interface (the first index on the interface is 0)Uicollection collection=NewUicollection (NewUiselector (). Index (0)); //2. Suppose you want to find all imagebuttom quantities        intCount=collection.getchildcount (NewUiselector (). ClassName ("Android.widget.ImageButton")); //3. Output the resultSystem.out.println ("ImageButton Conut is:" +count); //Example Two: if Teblecollection.getchildcount () does not add a parameter in parentheses only to find his direct subclass number//1. Search for a collection of components with the class name Android.widget.TableRowUicollection teblecollection=NewUicollection (NewUiselector (). ClassName ("Android.widget.TableRow")); //2. Returns the number of direct subclasses (the direct subclass refers to the component below the current subclass does not return)        intTeblechildcount=Teblecollection.getchildcount (); //3. Number of direct sub-classes of outputSystem.out.println ("Android.widget.TableRow:" +teblechildcount); }

Detailed description of the 4.UiCollection API

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.