I am creating an application that requires a single row of data to be retrieved during each click of a button.
I have created a DataBaseHelper class which calls and retrieves a random record from the database once the activity has been instantiated and the value displayed through a textview. However I am having trouble with retrieving the next or previous record as I can’t appear to access the DataBaseHelper class for position values from the button specification mentioned below.
Button btn_quotes = (Button) findViewById(R.id.btn_random_quote);
btn_quotes.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
I have checked on-line and through various articles but cannot find anything suitable. Please help?
In addition,
The instance of the database class is called,
DataBaseHelper myDbHelper = new DataBaseHelper(this);
myDbHelper = new DataBaseHelper(this);
However the instance within the onCreate method cannot be referenced within the onClick method. This is where I am struggling.
Getting the error:
Cannot refer to a non-final variable myDbHelper inside an inner class defined in a different method
mCursor.moveToNext()= for next andmCursor.moveToPrevious()= for previous….