2017-02-17 274 views
-4
roomNames = new ArrayList<>(); 

ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.select_dialog_item, roomNames); 
      adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line); 
      roomSpinner.setAdapter(adapter); 

if (item.getGroupId() == 0) { 
    /////please any one can help me how to save roomNames value in database 

} 
Thank you 
+0

,請閱讀以下:[第1頁](HTTP:// stackoverflow.com/help/how-to-ask)[page2](http://stackoverflow.com/help/mcve)[page3](http://stackoverflow.com/help/on-topic) –

回答

0

試試這個在SQLite數據庫Android的一個ArrayList中添加一個值,

插入所有的數據到數據庫

public void insert_data() { 

    SQLiteDatabase db = this.getWritableDatabase(); 

    for (int i = 0; i < roomNames.size(); i++) { 

     ContentValues values = new ContentValues(); 

     values.put(KEY_DATE, roomNames.get(i)); 

     // insert row 
     db.insert(TABLE_DATA, null, values); 
    } 
    if (db != null) { 
     db.close(); 
    } 
}