Greetings there.
For the purposes of my application, I'm trying to take information stored inside of an SQLite database and have the Strings stored inside of a table show up on one of my tabbed fragments. Unfortunately I haven't been able to find a good online resource to aid me in such matters so I've been bumbling around a bit trying to find a solution to this issue. So any help in the matter I would appreciate.
I have to apologise in advance to the fact that I'm still learning these things on the fly so there may be something obvious I've missed. At any rate thanks for your time.
For the SQLite helper there isn't any problems buidling, drawing information out of, and editing the database. This is just here for context.
SQLite Setup
Here's where the crux my problem lies. It doesn't recognize (this) in the setupDataHelper = new SetupDataHelper(this) in the fragment so the program isn't able to recognize the code properly and throws everything out of the loop.
Setup Fragment
I appreciate your time taken to look this over. If you know of any resource or if there's something I missed that would help me out I'd appreciate it immensely. Thank you.
For the purposes of my application, I'm trying to take information stored inside of an SQLite database and have the Strings stored inside of a table show up on one of my tabbed fragments. Unfortunately I haven't been able to find a good online resource to aid me in such matters so I've been bumbling around a bit trying to find a solution to this issue. So any help in the matter I would appreciate.
I have to apologise in advance to the fact that I'm still learning these things on the fly so there may be something obvious I've missed. At any rate thanks for your time.
For the SQLite helper there isn't any problems buidling, drawing information out of, and editing the database. This is just here for context.
SQLite Setup
Code:
public class SetupDataHelper extends SQLiteOpenHelper {
private static final int DB_VERSION = 7;
private static final String DB_NAME = "SetupDB";
private static final String TABLE_NAME = "setup";
private static final String CREATE_QUERY =
"CREATE TABLE " + TABLE_NAME + " (" +
"_id INTEGER NOT NULL PRIMARY KEY, " +
"name TEXT NOT NULL, " +
"password TEXT NOT NULL, " +
"merchemail TEXT NOT NULL, " +
"programversion TEXT NOT NULL, " +
"businessname TEXT NOT NULL, "+
"legal TEXT NOT NULL)";
private static final String INSERT_QUERY =
"INSERT INTO setup " +
"(name, password, merchemail, programversion, businessname, legal) " +
"VALUES " +
"('Joe Schmoe', 'RADICALDUDE', 'someone@blah.com', '0.01', 'Daves House of Snacks', 'legal')";
SetupDataHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_QUERY);
db.execSQL(INSERT_QUERY);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//delete the old table data, then re-create the table(s):
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
this.onCreate(db);
}
}
Here's where the crux my problem lies. It doesn't recognize (this) in the setupDataHelper = new SetupDataHelper(this) in the fragment so the program isn't able to recognize the code properly and throws everything out of the loop.
Setup Fragment
Code:
public class Setup extends Fragment {
public static SetupDataHelper setupDataHelper = null;
public static SQLiteDatabase setupDB = null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_setup, container, false);
return rootView;
}
@Override
public void onResume()
{
super.onResume();
setupDataHelper = new SetupDataHelper(this);
setupDB = setupDataHelper.getWritableDatabase();
EditText setupLoginEdit = (EditText) getView().findViewById(R.id.setupLoginText);
EditText setupPasswordEdit = (EditText) getView().findViewById(R.id.setupPasswordText);
EditText setupMerchEmailEdit = (EditText) getView().findViewById(R.id.setupMerchEmailText);
EditText setupProgVersionEdit = (EditText) getView().findViewById(R.id.setupProgVersionText);
EditText setupBusinessNameEdit = (EditText) getView().findViewById(R.id.setupBusinessNameText);
EditText setupLegalEdit = (EditText) getView().findViewById(R.id.setupLegalText);
Cursor c=setupDB.rawQuery("SELECT * FROM setup", null);
if(c.moveToFirst())
{
int id = c.getInt(0);
setupLoginEdit.setText(c.getString(1));
setupPasswordEdit.setText(c.getString(2));
setupMerchEmailEdit.setText(c.getString(3));
setupProgVersionEdit.setText(c.getString(4));
setupBusinessNameEdit.setText(c.getString(5));
setupLegalEdit.setText(c.getString(6));
}
else
{
Toast.makeText(this, "There was an error in compiling", Toast.LENGTH_SHORT).show();
}
}
}
I appreciate your time taken to look this over. If you know of any resource or if there's something I missed that would help me out I'd appreciate it immensely. Thank you.