我創建了一個SQLite數據庫並在其中存儲了字符串,並希望它在recyclerView內的textview中顯示。我應該如何初始化數組?使用SQLite在recyclerView中顯示字符串數組
DatabaseHelper:
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "Student.db";
public static final String TABLE_NAME = "student_table";
public static final String Col_1 = "ID";
public static final String Col_2 = "Title";
public static final String Col_3 = "Content";
public static final String Col_4 = "Remarks";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
SQLiteDatabase db = this.getWritableDatabase();
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table " +TABLE_NAME+"(ID INTEGER PRIMARY KEY AUTOINCREMENT, Title TEXT, Content TEXT, Remarks TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS"+TABLE_NAME);
}
}
,這是我的初始化cardView:
private void initializeCardItemList(){
CardItemModel cardItemModel;
/*String[] cardTitles = getResources().getStringArray(R.array.cat1_cards);
String[] cardContents = getResources().getStringArray(R.array.cat1_cards_content); */
final int length = cardTitles.length;
for(int i=0;i<length;i++){
cardItemModel = new CardItemModel(cardTitles[i],cardContents[i]);
cardItems.add(cardItemModel);
}
}
你真的應該使用一個數據庫的Arraylist,但你的答案是:寫一個'SELECT'查詢。請[編輯]您的問題,以包括一些解決方案的嘗試,以便我們可以看到你卡在哪裏 –
你試過'ArrayList'而不是使用典型的數組? –