标签:
用ListView实现对数据库的内容显示
MyBase base = new MyBase();
SQLiteDatabase db = mySQLhelpes.getReadableDatabase();
Cursor cursor = db.query("inof", null, null, null, null, null, null);
list = new ArrayList<Fuwu>();
while(cursor.moveToNext()){ //将数据写入ArrayList中
Fuwu fuwu = new Fuwu();
String name = cursor.getString(cursor.getColumnIndex("name") );
String num = cursor.getString(cursor.getColumnIndex("number"));
fuwu.setName(name);
fuwu.setNum(num);
list.add(fuwu);
fuwu = null;
}
db.close();
MyBase myBase = new MyBase(); //加载适配器
myBase.notifyDataSetChanged();//刷新适配器
lv.setAdapter(myBase);
a) 实现方法
public int getCount() //返回数据的个数
public View getView(int arg0, View arg1, ViewGroup arg2) //返回view值
View view = View.inflate(MainActivity.this, R.layout.item, null); //将xml转化为view
TextView tv_name = (TextView) view.findViewById(R.id.item_text_1);//得到子孩子
TextView tv_num = (TextView)view.findViewById(R.id.item_text_2);
tv_name.setText(list.get(arg0).getName());//数据载入
tv_num.setText(list.get(arg0).getNum());
标签:
原文地址:http://www.cnblogs.com/tangwanzun/p/5702271.html