Android : How to declare a variable of a class extending SQLiteOpenHelper in a fragment?

on Thursday, April 16, 2015


I must declare the following variable in a class extending Fragment:



public class CarrelloFragment extends Fragment {

DatabaseHelper sqLite=new DatabaseHelper(this); //here is the error


The constructor of DatabaseHelper class does not allow to do this with a fragment.


Here is the code of the constructor of DatabaseHelper class that extends SQLiteOpenHelper:


public class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "MySupermarket.db";



private static final int SCHEMA_VERSION = 2;

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

0 comments:

Post a Comment