-1

我想显示从 sqlite 到 textview 的数据,这是我的代码。我没有错。它没有显示数据没有错误,但主类崩溃

private void loadTextViewData()
{
DatabaseHandler db = new DatabaseHandler(getApplicationContext());
List<String> lables = db.getAllLabels();
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,android.R.layout.test_list_item, lables);

text.setText(??);                   
} 

sql类

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

        // Select All Query
        String selectQuery = "SELECT  * FROM " + TABLE_LABELS;

        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(1));
            } while (cursor.moveToNext());
        }

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

        // returning lables
        return labels;
    }
4

1 回答 1

0

而不是 ArrayAdapter 使用例如 SimpleCursorAdapter(或 CursorAdapter 的任何子类)

于 2013-06-11T08:53:02.750 回答