• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Android back button - retreating up through database rows

Lylio

Lurker
Ahoy folks,

I've been seriously helped out on this forum, and I just wanted to say a big thank you to the community and in particular LV426 who solved a big headache I had.

If I may, there's one final bug/issue that I'm struggling with it's an app that is for school/college students. When I open up a display page to display the information, the 'back' button of the Android phone retreats up each row of the database instead of just closing the display window. This video probably demonstrates it better than me trying to explain it: https://www.youtube.com/watch?v=h-uXcwe2-CY

Is there any chance anyone could point me to where I should start experimenting with a solution for this issue (I understand you folks might be reluctant to write code for me - but perhaps a pointer wouldn't be too much of a big ask?).

My current code can be found at: https://github.com/Lylio/GradeRunner

With the specific examples of databases and database helpers here:

Grades database - https://github.com/Lylio/GradeRunne...lylechristine/graderunner/GradesActivity.java

Grades database helper - https://github.com/Lylio/GradeRunne...ristine/graderunner/GradesDatabaseHelper.java

Cheers everyone, I really appreciate the help you've already provided in this forum, and any help you can offer on this issue would be a winner. And LV426, thank you so much for your time and help so far on this project.

All the best, and many thanks,

Lylio
 
This code

Code:
while(data.moveToNext()) {
  buffer.append("ID: " + data.getString(0) + "\n");
  buffer.append("Course name: " + data.getString(1) + "\n");
  buffer.append("Assignment: " + data.getString(2) + "\n");
  buffer.append("Grade: " + data.getString(3) + "\n");
  buffer.append("Feedback: " + data.getString(4) + "\n");
  buffer.append("\n");
  display("All Stored Data:", buffer.toString());
}

You're calling display() on each iteration of this loop, which displays a new alert dialog each time you append record details. I suspect it would work better if you built your entire String, then called display() after the loop completes:

Code:
while(data.moveToNext()) {
  buffer.append("ID: " + data.getString(0) + "\n");
  buffer.append("Course name: " + data.getString(1) + "\n"); 
  buffer.append("Assignment: " + data.getString(2) + "\n");
  buffer.append("Grade: " + data.getString(3) + "\n");
  buffer.append("Feedback: " + data.getString(4) + "\n");
  buffer.append("\n");
}
display("All Stored Data:", buffer.toString());
 
Hey LV426, your logic on this problem makes perfect sense. But it's causing my app to crash when I click the 'view data' button. For example, if I implement your code example as:
view_method.jpg


The app crashes when the the 'view data' button is clicked. Am I missing something obvious here?

Cheers mate,

Lylio
 
Is pasting the logcat code enough? - I can make a video too if that would be more helpful. Here's the logcat output when it crashes:

logcat.jpg


And that crash happens with this 'view data' button code:

viewdata.jpg


Cheers man,

Lylio
 
The error message is pretty clear. You're trying to get column 4 (Feedback) from the result set, which doesn't exist.
Btw the code you present here is now out of sync with the stuff on Github, making it even more difficult to answer your questions.
 
Ah of course, of course, of course, sorry I was looking at this issue after very little sleep and see what a foolish error I made there. I have now implemented your instructions, everything work great, I have published the corrected, functioning code to my GitHub repo, and once again I am absolutely indebted to you for your generous assistance. Many thanks LV426, you are truly a hero among heroes and I have learned much from your kind assistance. Cheers pal.
 
Back
Top Bottom