samedi 2 janvier 2016

Android studio Showing Data from database into the TextView

Here's my handler I dont know if after creating the table I can insert a data right away also i've followed this tutorial http://ift.tt/1qujYy9

    public class MyDBHandler extends SQLiteOpenHelper{

    private static final int DATABASE_VERSION = 1;
    private static final String DATABASE_NAME = "SchoolarDB.db";
    private static final String TABLE_SCHOOL = "School";

    public static final String COLUMN_ID = "ID";
    public static final String COLUMN_POSTAL = "Postal";
    public static final String COLUMN_TOP = "Top";
    public static final String COLUMN_NAME = "Name";
    public static final String COLUMN_REGION = "Region";
    public static final String COLUMN_LUZVINMIN = "LuzVinMin";
    public static final String COLUMN_LOCATION = "Location";
    public static final String COLUMN_INTRODUCTION = "Introduction";
    public static final String COLUMN_MISSION = "Mission";
    public static final String COLUMN_VISION = "Vision";
    public static final String COLUMN_ALUMNI = "Alumni";


    public MyDBHandler(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String CREATE_SCHOOL_TABLE = "CREATE TABLE " +
                TABLE_SCHOOL + "("
                + COLUMN_ID + " INTEGER PRIMARY KEY," + COLUMN_POSTAL
                + " INTEGER," + COLUMN_TOP + " INTEGER" + COLUMN_NAME + " TEXT,"
                + COLUMN_REGION + " TEXT" + COLUMN_LUZVINMIN + " TEXT" + COLUMN_LOCATION + " TEXT"
                + COLUMN_INTRODUCTION + " TEXT" + COLUMN_MISSION + " TEXT" + COLUMN_VISION + " TEXT"
                + COLUMN_ALUMNI + " TEXT" + ")";
        db.execSQL(CREATE_SCHOOL_TABLE);

        String INSERT_DATA_INTO_SCHOOL = "INSERT INTO " + TABLE_SCHOOL + " VALUES (1,3101,200,'Wesleyan University Philipphines'," +
                "'Region 3','Luzon','Nueva Ecija','WUP Intro','WUP Mission','WUP Vision','WUP Alumni')";
        db.execSQL(INSERT_DATA_INTO_SCHOOL);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion,
                          int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_SCHOOL);
        onCreate(db);
    }

}

Here's my db

    public class DBSchool {

    private int School_ID, School_Postal, School_Top;
    private String School_Name, School_Region, School_LuzVinMin, School_Location,
            School_Introduction, School_Mission, School_Vision, School_Alumni;

    public DBSchool(){

    }

    public DBSchool(int ID, int Postal, int Top, String Name, String Region,
                    String LuzVinMin, String Location, String Introduction,
                    String Mission, String Vision, String Alumni){

        this.School_ID = ID;
        this.School_Postal = Postal;
        this.School_Top = Top;
        this.School_Name = Name;
        this.School_Region = Region;
        this.School_LuzVinMin = LuzVinMin;
        this.School_Location = Location;
        this.School_Introduction = Introduction;
        this.School_Mission = Mission;
        this.School_Vision = Vision;
        this.School_Alumni = Alumni;

    }

    public DBSchool(int Postal, int Top, String Name, String Region,
                         String LuzVinMin, String Location, String Introduction,
                         String Mission, String Vision, String Alumni){

        this.School_Postal = Postal;
        this.School_Top = Top;
        this.School_Name = Name;
        this.School_Region = Region;
        this.School_LuzVinMin = LuzVinMin;
        this.School_Location = Location;
        this.School_Introduction = Introduction;
        this.School_Mission = Mission;
        this.School_Vision = Vision;
        this.School_Alumni = Alumni;

    }

    public void setID(int ID){

        this.School_ID = ID;
    }

    public int getID() {
        return this.School_ID;
    }

    public void setPostal(int Postal){

        this.School_Postal = Postal;
    }

    public int getPostal() {
        return this.School_Postal;
    }

    public void setTop(int Top){

        this.School_Top = Top;
    }

    public int getTop() {
        return this.School_Top;
    }

    public void setName(String Name){

        this.School_Name = Name;
    }

    public String getName() {
        return this.School_Name;
    }

    public void setRegion(String Region){

        this.School_Region = Region;
    }

    public String getRegion() {
        return this.School_Region;
    }

    public void setLuzVinMin(String LuzVinMin){

        this.School_LuzVinMin = LuzVinMin;
    }

    public String getLuzVinMin() {
        return this.School_LuzVinMin;
    }

    public void setLocation(String Location){

        this.School_Location = Location;
    }

    public String getLocation() {
        return this.School_Location;
    }

    public void setIntroduction(String Introduction){

        this.School_Introduction = Introduction;
    }

    public String getIntroduction() {
        return this.School_Introduction;
    }

    public void setMission(String Mission){

        this.School_Mission = Mission;
    }

    public String getMission() {
        return this.School_Mission;
    }

    public void setVision(String Vision){

        this.School_Vision = Vision;
    }

    public String getVision() {
        return this.School_Vision;
    }

    public void setAlumni(String Alumni){

        this.School_Alumni = Alumni;
    }

    public String getAlumni() {
        return this.School_Alumni;
    }

}

What I want to happen is to retrieve the data and put it into a textview, help pls

Aucun commentaire:

Enregistrer un commentaire