【问题标题】:is it possible to retrieve texts and images from the same SQLite database是否可以从同一个 SQLite 数据库中检索文本和图像
【发布时间】:2020-06-18 21:00:28
【问题描述】:

在我的情况下,我有一个数据库,它有 4 列 1.id、2 Sticker_Name、3 Sticker_author,第四个是 IMAGE,我知道如何从数据库中检索特定列,但我的问题是当我检索特定列时从 SQLite 中,图像也被检索并显示在 recyclerListView 中,我不明白我能做些什么来解决这些问题。

这是我的代码..

要从数据库中检索特定列,它工作得很好,但是当我保存在数据库中的第二个活动中时,图像也会显示在 recyclerListView 中..

 private void fetchdat(){
    word_list = new ArrayList<>();
    SQLiteDatabase sd=mydb.getWritableDatabase();
    Cursor cursor1=sd.query("stickerstable",new String[] {STICKER_AUTHOR},null,null,null,null,null);
   if (cursor1.moveToFirst()){
       do {

           word_list.add(new data_items(
                   cursor1.getString(cursor1.getColumnIndex(STICKER_AUTHOR))
           ));
       }while (cursor1.moveToNext());
       cursor1.close();
       sd.close();
   }

    mAdapter = new recycle_Adapter(word_list);
    recyclerView.setAdapter(mAdapter);
}

这里是代码

因此,我从 SQLite 数据库中检索所有列数据。

  private void FetchData(){
    word_list = new ArrayList<>();
     SQLiteDatabase sd = mydb.getWritableDatabase();
    Cursor cursor = sd.query("stickerstable",null, null, null, null, null, null);
    if (cursor.moveToFirst()){
        do{
            word_list.add(new data_items(
                    cursor.getInt(cursor.getColumnIndex(ID)),
                    cursor.getString(cursor.getColumnIndex(STICKER_AUTHOR)),
                    cursor.getString(cursor.getColumnIndex(STICKER_NAME)
                     )));

        }

        while (cursor.moveToNext());
        cursor.close();
        sd.close();
    }


     mAdapter = new recycle_Adapter(word_list);
    recyclerView.setAdapter(mAdapter);


  }

【问题讨论】:

    标签: java android database sqlite android-sqlite


    【解决方案1】:

    也许这对你有帮助:

    private List<String> getAuthorList () {
                List<String> authorList = new ArrayList<>();
                try {
                    SQLiteDatabase sd = mydb.getWritableDatabase();
                    Cursor cursor = sd.rawQuery(
                            "SELECT Sticker_author FROM " + tableName + " WHERE <here is your condition> ", null);
    
                    if (cursor.getCount() > 0) {
                        cursor.moveToFirst();
    
                        while (!cursor.isAfterLast()) {
                            String author    = cursor.getString(0);
                            authorList.add(author);
                            cursor.moveToNext();
                        }
    
                        if (cursor != null) {
                            cursor.close();
                        }
    
                    }
    
                } catch (Exception e) {
                    e.printStackTrace();
                }
    
                return authorList;
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-11
      • 2011-09-24
      • 2015-08-01
      • 2021-01-28
      • 2023-03-03
      • 1970-01-01
      • 2012-12-10
      • 2015-12-10
      相关资源
      最近更新 更多