用ListView实现对数据库的内容显示

  1. 创建一个触发机制 ---------(作用)将数据读入ArrayList集合中

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);

  1. 定义一个ListView-----(作用)把数据从集合中放入ListView中
  2. 找到ListView
  3. 定义一个复杂的BaseAdapeter

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());

  1. 给ListView设置Adapter

最新文章

  1. php查询文件扩展名
  2. C#并行编程-相关概念
  3. HTTP/2.0与HTTP/1.1协议区别
  4. php引入lucene方法
  5. Oracle在dos命令下导出导入
  6. clientTop、clientWidth、offsetTop、offsetWidth、scrollTop
  7. globalCompositeOperation 学习
  8. Java引用数据类型
  9. oracle查询锁表解锁语句
  10. Vuex 最简单的数量增减实例
  11. ifconfig 网卡 下面的参数
  12. redis scan删除key的方法封装
  13. LeetCode: 2_Add Two Numbers | 两个链表中的元素相加 | Medium
  14. python知识补足
  15. Python 发射导弹的正确方式
  16. javascript的fn方法(转)
  17. 百度地图VUE-REACT
  18. Linux内核中断处理机制
  19. Python 爬虫知识点 - 淘宝商品检索结果抓包分析
  20. 20155210潘滢昊 2016-2017-2《Java程序设计》第一周学习总结

热门文章

  1. 微信小程序教程(第一篇)
  2. 蓝桥网试题 java 基础练习 矩形面积交
  3. Github+Hexo搭建静态博客
  4. 为什么Java可以跨平台,而其他语言不行
  5. C语言 extern3 全局变量的使用
  6. JavaScript null 和 undefined
  7. c#访问存储过程
  8. 检查浏览器url改变,处理ajax前进和后退键
  9. weex官方demo weex-hackernews代码解读(下)
  10. List&lt;bean&gt;转换Jsonarray知识心得