我需要帮助来创建一个显示数据库 sql 元素的列表视图。首先Text1,Text2 and Text3
在我的活动中创建了一个带有 3 个字段 TextView 的小型 xml 布局:和一个列表视图。在我对界面中的列进行分组之后
public interface TableRegistry extends BaseColumns{
String TABLE_NAME = "Registry";
String TYPE = "Type";
String DATE = "Date";
String STATUS = "Status";
String NUMBER = "Number";
String MESSAGE = "Message";
String OTHER = "Other";
String[] COLUMNS = new String[]
{ _ID, TYPE, DATE, STATUS, NUMBER, MESSAGE, OTHER };
}
在我创建数据库类之后..
public class APdatabaseClass extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "APdatabase";
private static final int DATABASE_VERSION = 1;
public APdatabaseClass(Context context) {
super(context, DATABASE_NAME , null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
String sql = "CREATE TABLE {0} ({1} INTEGER PRIMARY KEY AUTOINCREMENT," +
" {2} TEXT NOT NULL,{3} TEXT NOT NULL,{4} TEXT NOT NULL,{5} TEXT NOT NULL,{6} TEXT NOT NULL, {7} TEXT NOT NULL);";
db.execSQL(MessageFormat.format(sql, TableRegistry.TABLE_NAME, TableRegistry._ID,
TableRegistry.TYPE, TableRegistry.DATE, TableRegistry.STATUS, TableRegistry.NUMBER, TableRegistry.MESSAGE, TableRegistry.OTHER));
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + TableRegistry.TABLE_NAME);
// Create tables again
onCreate(db);
}
现在如何使用 SimpleCursorAdapter 或其他东西将我的数据库连接到我的活动中的列表视图?我需要用以下内容填充 3 个 TextView 字段:
TableRegistry.TYPE, TableRegistry.DATE, TableRegistry.STATUS.
提前致谢!