• 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);
        }
  • 相关阅读:
    求字符串长度
    n人围圈报数,报3出圈
    设计模式-桥梁模式(11)
    ajax
    数组右移
    数组元素交换
    倒序输出(指针方法)
    myeclipse6.5使用tomcat7报java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory错
    设计模式-组合模式(10)
    刷评论脚本
  • 原文地址:https://www.cnblogs.com/zychen/p/7384762.html
Copyright © 2020-2023  润新知