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 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
// 获取ListView
ListView lv = (ListView) this.findViewById(R.id.listView);
// 生成List>数据
List
for (Contact contact : contacts) {
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
更多精彩
赞助商链接