展会信息港展会大全

Android ApiDemos示例解析(120):Views->Gallery->2. People
来源:互联网   发布日期:2015-10-03 10:44:44   浏览:1945次  

导读:SimpleCursorAdapter 的构造函数如下public SimpleCursorAdapter(Context context, int layout, Cursor c, St...

SimpleCursorAdapter 的构造函数如下

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

context: context对象,可以使用activity。

layout: layout 资源ID simple_gallery_item.xml

cursor: cursor对象,本例为通讯录cursor.

from: 需要显示的列名数组

to: 列对应的View 的id

[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 to...

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 to...

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);

本例Adapter 使用的View为TextView (id 为 android.R.id.text1) ,因此 Gallery显示的为联系人的人名。

作者:mapdigit

赞助本站

人工智能实验室

相关热词: android开发 教程

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港