Android:SQLite数据绑定ListView

来源:互联网 发布:vr用什么软件 编辑:程序博客网 时间:2024/06/05 14:17
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 + "\n");                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);    }
0 0
原创粉丝点击