从自定义列表对象中读取

时间:2015-09-20 13:39:13

标签: android android-listview android-sqlite android-recyclerview

我在Sqlite数据库中有一些企业,其定义方法如下:

//获取所有ComplainMessageWhatevers public List getAllComplainMessageWhatever(){

List<ComplainMessageWhatever> cmwList = new ArrayList<ComplainMessageWhatever>();
// Select All Query
String selectQuery = "SELECT  * FROM " + TABLE_COMPLAIN_MESSAGE_WHATEVER;

SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);

// looping through all rows and adding to list
if (cursor.moveToFirst()) {
    do {
        ComplainMessageWhatever cmw = new ComplainMessageWhatever();
        cmw.setID(Integer.parseInt(cursor.getString(0)));
        cmw.setName(cursor.getString(1));
        cmw.setPhoneNumber(cursor.getString(2));
        // Adding cmw to list
        cmwList.add(cmw);
    } while (cursor.moveToNext());
}

// return cmw list
return cmwList;

}

在我的活动中,我这样做:

  DatabaseHandler dh = new DatabaseHandler(this);


        List<ComplainMessageWhatever> d1 = dh.getAllComplainMessageWhatever();

现在我不知道如何从该列表中提取值,例如电话号码,消息等,并将它们显示在RecyclerView(Mateiral Design Cards)中。

我该怎么做?我应该发布DatabaseHandler类吗?

0 个答案:

没有答案