我需要幫助創建一個顯示數據庫sql的元素的列表視圖。 首先創建一個帶有3個字段的TextView的小型XML佈局:Text1,Text2 and Text3
和我的活動中的一個列表視圖。 後,我已經在接口Android:在ListView上的Sqlite
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什麼活動的ListView?我需要填充3個TextView字段:
TableRegistry.TYPE, TableRegistry.DATE, TableRegistry.STATUS.
在此先感謝!
感謝您的回答! – Tony 2012-04-13 19:34:01