首页 > 代码库 > 赵雅智_ListView_SimpleAdapter

赵雅智_ListView_SimpleAdapter

项目步骤

  1. 声明listView控件并获取显示的视图
  2. 获取显示的数据
  3. 设置显示的adapter
  4. 注册点击事件

具体案例

实现效果:

查找的方法

public List<Map<String, Object>> getData() {
		SQLiteDatabase db = dh.getWritableDatabase();
		List<Map<String, Object>> data = http://www.mamicode.com/new ArrayList>();>

布局文件

同BaseAdapter的布局文件activity_main.xml
http://blog.csdn.net/zhaoyazhi2129/article/details/29636669

ArrayAdapter实现类(主程序)


package com.example.android_sqlite;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;

import com.example.android_sqlite.dao.impl.UserDaoImpls;
import com.example.android_sqlite.database.DatabaseHelper;

/**
 * SimpleAdapter
 * 
 * @author zhaoyazhi
 * 
 */
public class MainActivity extends Activity implements OnItemClickListener {
	private ListView lv_users;// 视图层

	// model层 相关的对象的声明
	private DatabaseHelper dh;
	private UserDaoImpls userDao;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		// 模型层
		dh = new DatabaseHelper(this);// 创建数据库
		userDao = new UserDaoImpls(dh);// 获取显示数据 model
		List<Map<String, Object>> data = http://www.mamicode.com/userDao.getData();// 查询获取数据>