I need to process a SQLite dataset in an Android system.
In my dataBaseHelper file (DataBaseAccessor) I have the following code (which when attached to a listview shows the relevant data).
public static ArrayList<QuestionListQuestion> getQuestionListQuestions(long id){
String qry = "select QuestionListQuestionID, QuestionListQuestionQuestionListID, QuestionListQuestionQuestionID, QuestionListQuestionSortOrder, QuestionListQuestionSupplementalQuestionIDYes, QuestionListQuestionSupplementalQuestionIDNo, QuestionListQuestionSupplementalQuestionIDText, QuestionListQuestionSurveyGroupID from QuestionListQuestion where QuestionListQuestionQuestionListID=" + id;
ArrayList<QuestionListQuestion> list = new ArrayList<QuestionListQuestion>();
try{
Cursor cursor = wdb.rawQuery(qry, null);
while (cursor.moveToNext()) {
QuestionListQuestion questionlistquestion = new QuestionListQuestion();
questionlistquestion.QuestionListQuestionID = cursor.getLong(0);
questionlistquestion.QuestionListQuestionQuestionListID = cursor.getLong(1);
questionlistquestion.QuestionListQuestionQuestionID = cursor.getLong(2);
questionlistquestion.QuestionListQuestionSortOrder = cursor.getLong(3);
questionlistquestion.QuestionListQuestionSupplementalQuestionIDYes = cursor.getString(4); questionlistquestion.QuestionListQuestionSupplementalQuestionIDNo = cursor.getString(5);
questionlistquestion.QuestionListQuestionSupplementalQuestionIDText = cursor.getString(6);
questionlistquestion.QuestionListQuestionSurveyGroupID = cursor.getLong(7);
list.add(questionlistquestion);
}
cursor.close();
}
catch (Exception e) {
e.printStackTrace();
}
return list;
}
I now need to extend the system so that I can process the data and create new records in another table based on the original list returned.
I tried the following attached to a button (selecting the relevant list ID from a spinner):-
QuestionListID = (String) SiteGenerateQuestions.this.spnQuestL.getSelectedItem().toString();
long SpinnerSelectedBT;
SpinnerSelectedBT = GenerateQuestions.this.spnQuestL.getSelectedItemId();
list = DatabaseAccessor.getQuestionListQuestions(SpinnerSelectedBT);
for (int i=0; i < list.size(); i++){
Toast.makeText(SiteGenerateQuestions.this," list.get(" + i + ") = " + list.get(i) + " " , Toast.LENGTH_SHORT).show();
}
The Toast displays the following:-
list.get(0) = com.tw.question.entity.QuestionListQuestion@407a6F70
list.get(1) = com.tw.question.entity.QuestionListQuestion@407bc170
etc...
How can I get access to the actual data instead of … .entity.QuestionListQuestion@407bc170 or am I completely off-track?
Many Thanks
I agree with @wsanville the
get()method will return the object in that location of the list. When you print out an object (in a toast, log, System.out.println etc) it will use thetoString()value in the printout. The defaulttoString()is the package name followed by @ which is followed by a hex representation of that object. Your class will need to override thetoString()method so when you useget()it will print out whatever you put in yourtoString()method.