Android ApiDemos example resolution (120): Views-& gt; Gallery-& gt; 2. P

Source: Internet
Author: User

The constructor of SimpleCursorAdapter is as follows:

Public SimpleCursorAdapter (Context context, int layout, Cursor c, String [] from, int [])

Context: context object. You can use activity.
Layout: layout resource ID simple_gallery_item.xml
Cursor: cursor object. In this example, it is the address book cursor.
From: array of column names to be displayed
To: id of the View corresponding to the column
[Java]
SpinnerAdapter adapter = new SimpleCursorAdapter (this,
// Use a template that displays a text view
Android. R. layout. simple_gallery_item,
// Give the cursor to the list adatper
C,
// Map the NAME column in the people database...
New String [] {People. NAME },
// The "text1" view defined in the XML template
New int [] {android. R. id. text1 });
 
Gallery g = (Gallery) findViewById (R. id. gallery );
G. setAdapter (adapter );

SpinnerAdapter adapter = new SimpleCursorAdapter (this,
// Use a template that displays a text view
Android. R. layout. simple_gallery_item,
// Give the cursor to the list adatper
C,
// Map the NAME column in the people database...
New String [] {People. NAME },
// The "text1" view defined in the XML template
New int [] {android. R. id. text1 });

Gallery g = (Gallery) findViewById (R. id. gallery );
G. setAdapter (adapter );


In this example, the View used by the Adapter is TextView (id is android. R. id. text1), so Gallery displays the contact's name.

 



Author: mapdigit
 

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.