Search in sources :

Example 1 with DaoMaster

use of com.greendao.sql.DaoMaster in project AndroidDevelop by 7449.

the class MainActivity method init.

private void init() {
    writableDatabase = new DaoMaster.DevOpenHelper(this, "greendao", null).getWritableDatabase();
    DaoSession daoSession = new DaoMaster(writableDatabase).newSession();
    //得到Dao的对象
    userDao = daoSession.getUserDao();
    // 遍历表中所有的数据
    Cursor cursor = writableDatabase.query(userDao.getTablename(), userDao.getAllColumns(), null, null, null, null, null);
    String[] from = { UserDao.Properties.UserName.columnName, UserDao.Properties.UserSex.columnName };
    int[] id = { android.R.id.text1, android.R.id.text2 };
    simpleCursorAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, cursor, from, id, Adapter.NO_SELECTION);
    listView.setAdapter(simpleCursorAdapter);
}
Also used : DaoMaster(com.greendao.sql.DaoMaster) SimpleCursorAdapter(android.widget.SimpleCursorAdapter) Cursor(android.database.Cursor) DaoSession(com.greendao.sql.DaoSession)

Aggregations

Cursor (android.database.Cursor)1 SimpleCursorAdapter (android.widget.SimpleCursorAdapter)1 DaoMaster (com.greendao.sql.DaoMaster)1 DaoSession (com.greendao.sql.DaoSession)1