Listview显示sqlite数据库

时间:2011-07-10 09:03:14

标签: android sqlite listview

我有一个用以下处理程序创建的数据库:

    public class DatabaseHelper extends SQLiteOpenHelper {
    private static final String DATABASE_NAME = "trade.db";
    public static final String RESOURCEID = "resourceid";
    public static final String STARTPRICE = "startprice";
    public static final String CURRENTBID = "currentbid";
    public static final String EXPIRES = "expires";
    public static final String BUYNOWPRICE = "buynowprice";
    public static final String TYPE = "type";

    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, 1); 
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL( "CREATE TABLE cards (_id INTEGER PRIMARY KEY AUTOINCREMENT, resourceid TEXT, startprice TEXT,currentbid TEXT, expires TEXT, buynowprice TEXT, type TEXT);");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        android.util.Log.w("cards",
                "Upgrading database, which will destroy all old data");
        db.execSQL("DROP TABLE IF EXISTS ");
        onCreate(db);
    }
}

我想在listview中显示这个DB的项目,其中项目是可选择的,不幸的是我是一个完整的android nooby(第一个应用程序)。有人可以向我解释我会怎么做?我很清楚那里有一些例子,但我根本无法遵循它们。感谢

2 个答案:

答案 0 :(得分:1)

没有教程,只需要一些你需要的东西:

答案 1 :(得分:0)

我可以给你一个如何展示它的完整例子......但它会让你变得懒惰......无论我能指导你什么......就像你必须为ListView创建一个布局ListView项目的布局......您也可以在不创建这些布局的情况下执行此操作......但无论您需要创建adapter,都可以SimpleAdapter ...您必须按HashMap放置该适配器的记录...如下例所示:

 
SimpleAdapter adapter = new SimpleAdapter(this,appntmntHistoryList,R.layout.appointment_history_text,new String[] {"date","appntmnt_id"},new int[] {R.id.appDateHist, R.id.appWithFakeHist});
appointmentHistory.setAdapter(adapter);  

此过程用于通过

HashMap
从数据库存储中获取键/值对中的记录...

相关问题