Added further Database integration
This commit is contained in:
parent
4924a384a2
commit
2d8df647cf
@ -2,13 +2,19 @@ package org.ddnss.sfs.git.wdg.vokabel_trainer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class DataHandler {
|
||||
public static final String DATABASENAME = "vocabDB";
|
||||
public static final int DATABASE_VERSION = 1;
|
||||
|
||||
public static final String TABLE_NAME = "vocabTable";
|
||||
public static final String DEUTSCH = "deutsch";
|
||||
public static final String GERMAN = "german";
|
||||
public static final String ENGLISH = "english";
|
||||
|
||||
private Context ctx;
|
||||
@ -35,4 +41,22 @@ public class DataHandler {
|
||||
public void addEntry(String voc1, String voc2){
|
||||
db.execSQL("insert into vocabTable (deutsch, english) values ('vocab1', 'vocab2')");
|
||||
}
|
||||
|
||||
private static class DataBaseHelper extends SQLiteOpenHelper {
|
||||
|
||||
public DataBaseHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
|
||||
super(context, DATABASENAME, null, DATABASE_VERSION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
String command = "create table if not exists vocTable(german text not null, englisch text not null);";
|
||||
db.execSQL(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ import androidx.navigation.ui.NavigationUI;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private DataHandler dbHandler;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -26,5 +28,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
|
||||
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
|
||||
NavigationUI.setupWithNavController(navView, navController);
|
||||
dbHandler = new DataHandler(this);
|
||||
}
|
||||
|
||||
public void addEntry(){
|
||||
|
||||
}
|
||||
}
|
@ -36,4 +36,15 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.186" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/addEntry"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="161dp"
|
||||
android:layout_marginTop="388dp"
|
||||
android:text="Einfügen"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Reference in New Issue
Block a user