WEB开发网
开发学院手机开发Android 开发 Android 数据存储 阅读

Android 数据存储

 2010-04-10 04:46:00 来源:WEB开发网   
核心提示:30. }31.32. }package com.contentProvider; import android.app.ListActivity; import android.database.Cursor; import android.os.Bundle; import android.provider.Con

30. }

31.

32. }

package com.contentProvider; import android.app.ListActivity; import android.database.Cursor; import android.os.Bundle; import android.provider.Contacts.Phones; import android.widget.ListAdapter; import android.widget.SimpleCursorAdapter; public class ContentProviderDemo extends ListActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //getContentResolver()方法得到应用的ContentResolver实例。 // query(Phones.CONTENT_URI, null, null, null, null)。它是ContentResolver里的方法,负责查询所有联系人,并返回一个Cursor。这个方法参数比较多,每个参数的具体含义如下。 //· 第一个参数为Uri,在这个例子里边这个Uri是联系人的Uri。 //· 第二个参数是一个字符串的数组,数组里边的每一个字符串都是数据表中某一列的名字,它指定返回数据表中那些列的值。 //· 第三个参数相当于SQL语句的where部分,描述哪些值是我们需要的。 //· 第四个参数是一个字符串数组,它里边的值依次代替在第三个参数中出现的“?”符号。 //· 第五个参数指定了排序的方式。 Cursor c = getContentResolver().query(Phones.CONTENT_URI, null, null, null, null); startManagingCursor(c); //让系统来管理生成的Cursor。 ListAdapter adapter = new SimpleCursorAdapter( this, android.R.layout.simple_list_item_2, c, new String[] { Phones.NAME, Phones.NUMBER }, new int[] { android.R.id.text1, android.R.id.text2 }); setListAdapter(adapter); //将ListView和SimpleCursorAdapter进行绑定。 } }

五. 网络存储方式

1.例子介绍

通过邮政编码查询该地区的天气预报,以POST发送的方式发送请求到webservicex.net站点,访问 WebService.webservicex.net站点上提供查询天气预报的服务,具体信息请参考其WSDL文档,网址为:

http://www.webservicex.net/WeatherForecast.asmx?WSDL。

输入:美国某个城市的邮政编码。

输出:该邮政编码对应城市的天气预报。

2.实现步骤如下

(1)如果需要访问外部网络,则需要在AndroidManifest.xml文件中加入如下代码申请权限许可:

< !-- Permissions -->

上一页  14 15 16 17 18 19 20 21  下一页

Tags:Android 数据 存储

编辑录入:coldstar [复制链接] [打 印]
赞助商链接