vendredi 28 août 2015

How to display Data from SQLite database in table layout?

I am a new in android so my apologies if this seems to be a silly question. I want to display data returned from the SQLite database. All of this data is show in tabular format like GridView or Table Layout to display this data. Thanks in advance.

Here is may DatabaseHandler.java file

// Getting All chemicals
    public List<Chemical_DB> getAllchemicals() {
        List<Chemical_DB> chem_List = new ArrayList<Chemical_DB>();
        // Select All Query
        String selectQuery = "SELECT  * FROM " + TABLE_CHEMICAL;

        SQLiteDatabase db = this.getWritableDatabase();
        Cursor cursor = db.rawQuery(selectQuery, null);

        // looping through all rows and adding to list
        if (cursor.moveToFirst()) {
            do {
                Chemical_DB  chem= new Chemical_DB();
                chem.setSerial(Integer.parseInt(cursor.getString(0)));
                chem.setDate(cursor.getString(1));
                chem.setName(cursor.getString(2));
                chem.setQuantity(cursor.getString(3));
                // Adding Chemical_DB to list
                chem_List.add(chem);
            } while (cursor.moveToNext());
        }

        // return Chemical_DB list
        return chem_List;
    }


And suggest me about xml file and Main_activity in java file too?? Only i want to data to show in table view or grid view?? I am very thankful to you..

Aucun commentaire:

Enregistrer un commentaire