我想将一个表的id和名称从sqlite数据库存储到spinner。我需要在一个微调器中存储两个列信息

时间:2016-08-12 05:52:49

标签: android sqlite

这里我只得到单个值并将其保存在spinner但我想在一个微调器中检索两个列值

public List<String> getAllLabels1(){
    List<String> labels = new ArrayList<String>();


    // Select All Query
    String selectQuery = "SELECT DISTINCT WeatherPrediction.CropID as CropID, Crop.Name as Name FROM Crop INNER JOIN " +
                  "WeatherPrediction ON Crop.CropID = WeatherPrediction.CropID order by Name";

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

    // looping through all rows and adding to list
    if (cursor.moveToFirst()) {
        do {
            labels.add(cursor.getString(0));
        } while (cursor.moveToNext());
    }

    // closing connection
    cursor.close();
    db.close();

    // returning lables
    return labels;
}

0 个答案:

没有答案