zoukankan      html  css  js  c++  java
  • Android:SQLite数据绑定ListView

    public void showDbUpdata(){
            mContext = MainActivity.this;
            myDBHelper = new DbOpenHelper(mContext, "note.db", null, 1);
    
            TextView note_main_content = (TextView) findViewById(R.id.content_main_textView_1);
    
            mydb = myDBHelper.getWritableDatabase();
            mydbcontent = new StringBuilder();
    
            Cursor cursor = mydb.query("note", null, null, null, null, null, null);
            //int columnsSize = cursor.getColumnCount();获取长度
            List<Map<String, Object>> listitem = new ArrayList<Map<String, Object>>();
            if (cursor.moveToFirst()) {
                do {
    
                    int noteid = cursor.getInt(cursor.getColumnIndex("noteid"));
                    String title = cursor.getString(cursor.getColumnIndex("title"));
                    String fenlei = cursor.getString(cursor.getColumnIndex("fenlei"));
                    String date = cursor.getString(cursor.getColumnIndex("date"));
                    //mydbcontent.append( noteid + ":" + title+":" + fenlei+":" + date + "
    ");
    
                    Map<String, Object> showitem = new HashMap<String, Object>();
                    showitem.put("icon", fenbie_icon_list[1]);
                    showitem.put("title", title);
                    showitem.put("fenlei", fenlei);
                    showitem.put("date", date);
                    showitem.put("number", 1);
                    listitem.add(showitem);
                } while (cursor.moveToNext());
            }
            cursor.close();
            //创建一个simpleAdapter
            SimpleAdapter myAdapter = new SimpleAdapter(getApplicationContext(), listitem, R.layout.main_list_item, new String[]{"icon","title", "date","number"}, new int[]{R.id.imageView_note_icon,R.id.textView_title, R.id.textView_date,R.id.textView_number});
            ListView listView = (ListView) findViewById(R.id.main_note_list);
            listView.setAdapter(myAdapter);
    
           // note_main_content.setText(mydbcontent);
        }
  • 相关阅读:
    UML中类图的符号解释
    Vim简明教程【CoolShell】
    C++ 指针—02 指针与引用的对照
    一个通用onReady函数的实现
    内存泄漏以及常见的解决方法
    个人博客之路
    WPF 设置WebBrowser控件不弹脚本错误提示框
    Solr使用入门指南
    用C语言写解释器(一)——我们的目标
    数据库索引的作用和长处缺点
  • 原文地址:https://www.cnblogs.com/zychen/p/7384762.html
Copyright © 2011-2022 走看看