package com.example.partition; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.os.Bundle; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; public class SponsorActivity extends AppCompatActivity { private TextView adTextView; private SQLiteDatabase db; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sponsor); adTextView = findViewById(R.id.adTextView); db = new DBHelper(this).getReadableDatabase(); updateAdText(); } private void updateAdText() { Cursor cursor = db.rawQuery("SELECT text FROM ad_table LIMIT 1", null); if (cursor.moveToFirst()) { adTextView.setText(cursor.getString(0)); } cursor.close(); } } Fichier DBHelper.java package com.example.partition; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; public class DBHelper extends SQLiteOpenHelper { public DBHelper(Context context) { super(context, "ads.db", null, 1); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE ad_table (text TEXT)"); db.execSQL("INSERT INTO ad_table VALUES ('Publicité initiale')"); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS ad_table"); onCreate(db); } } Fichier activity_sponsor.xml