WEB开发网
开发学院手机开发Android 开发 Android 数据存储之 SQLite嵌入式数据库 阅读

Android 数据存储之 SQLite嵌入式数据库

 2010-03-26 15:43:00 来源:WEB开发网   
核心提示:import android.view.View;import android.widget.AdapterView;import android.widget.ListView;import android.widget.SimpleAdapter;import android.widget.Toast;import

import android.view.View;

import android.widget.AdapterView;

import android.widget.ListView;

import android.widget.SimpleAdapter;

import android.widget.Toast;

import android.widget.AdapterView.OnItemClickListener;

public class AndroidSQLite extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

// 获取分页数据

ContactsService contactsService = new ContactsService(this);

List contacts = contactsService.getScrollData(0, 3);

// 获取ListView

ListView lv = (ListView) this.findViewById(R.id.listView);

// 生成List>数据

List> data = new ArrayList>();

for (Contact contact : contacts) {

HashMap item = new HashMap();

item.put("_id", contact.get_id());

item.put("name", contact.getName());

item.put("phone", contact.getPhone());

data.add(item);

}

// 生成Adapter

SimpleAdapter adapter = new SimpleAdapter(this, data,

R.layout.contactitem, new String[] { "_id", "name", "phone" },

new int[] { R.id.tv_id, R.id.tv_name, R.id.tv_phone });

// 设置ListView适配器

lv.setAdapter(adapter);

// 为ListView添加事件

lv.setOnItemClickListener(new OnItemClickListener() {

@Override

public void onItemClick(AdapterView parent, View view,

int position, long id) {

HashMap item = (HashMap) parent

上一页  7 8 9 10 11 12 13  下一页

Tags:Android 数据 存储

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