Sqlite load items from previous group
My database consist of 3 tables.
1 Levels (1 Level, 2 Level, 3 Level)
2 Test groups (5 Tests for Level 1, 10 Tests for Level 2...)
3 Test questions
There is problem when open tests from Level 2 and so on. Inside should be from related Level, but instead there will be tests from Level 1, then Level 2 and so on.
For example below I hardcoded: String selection = "quiz_list_id" + " = ? " + " AND " + "LevelID" + " = 2";.
So when I open Level 2 I see right number of Tests, but first 5 will be empty and from 6 to 10 I have tests for Level 2 from 1 to 4.
I understand that the problem is somehow related to that my Level 2 first Test has id 6 and first 5 are taken by Tests for Level 1.
How can I get those tests to start from beginning? Why previous Level tests are counted and therefore shift next Levels' Tests?
DBHelper.java
...
public ArrayList<Question> getNLevelQuestions(int quizListID) {
ArrayList<Question> questionList = new ArrayList<>();
db = getReadableDatabase();
String table = QuestionsTable.TABLE_NAME + " JOIN " + QuizListTable.TABLE_NAME +
" ON " + QuizListTable.QUIZ_ID + " = " + QuestionsTable.COLUMN_QUIZ_LIST_ID;
//String selection = QuestionsTable.COLUMN_QUIZ_LIST_ID + " = ? ";
//Below hardcoded version of string selection
String selection = "quiz_list_id" + " = ? " + " AND " + "LevelID" + " = 2";
String selectionArgs = new String{String.valueOf(quizListID)};
Cursor c = db.query(table,
null,
selection,
selectionArgs,
null,
null,
null
);
if (c.moveToFirst()) {
do {
Question question = new Question();
question.setId(c.getInt(c.getColumnIndex(QuestionsTable._ID)));
question.setQuestion(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_QUESTION)));
question.setOption1(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION1)));
question.setOption2(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION2)));
question.setOption3(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION3)));
question.setOption4(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION4)));
question.setAnswerNB(c.getInt(c.getColumnIndex(QuestionsTable.COLUMN_ANSWER_NB)));
question.setListTest(c.getInt(c.getColumnIndex(QuestionsTable.COLUMN_QUIZ_LIST_ID)));
questionList.add(question);
} while (c.moveToNext());
}
c.close();
return questionList;
}
}
QuizContractor.java
public final class QuizContract {
private QuizContract() {
}
public static class JLPTLevelsTable implements BaseColumns{
public static final String TABLE_NAME = "test_level";
public static final String COLUMN_NAME = "LevelName";
public static final String COLUMN_JLPTLevel_ID = "LevelID";
}
public static class QuizListTable implements BaseColumns{
public static final String TABLE_NAME = "quiz_list";
public static final String COLUMN_NAME = "name";
public static final String COLUMN_JLPTLevel_ID = "LevelID";
public static final String QUIZ_ID ="quiz_id";
}
public static class QuestionsTable implements BaseColumns {
public static final String TABLE_NAME = "quiz_questions";
public static final String COLUMN_QUESTION = "question";
public static final String COLUMN_OPTION1 = "option1";
public static final String COLUMN_OPTION2 = "option2";
public static final String COLUMN_OPTION3 = "option3";
public static final String COLUMN_OPTION4 = "option4";
public static final String COLUMN_ANSWER_NB = "answer_nb";
public static final String COLUMN_QUIZ_LIST_ID = "quiz_list_id";
}
}
I
sqlite arraylist android-sqlite
add a comment |
My database consist of 3 tables.
1 Levels (1 Level, 2 Level, 3 Level)
2 Test groups (5 Tests for Level 1, 10 Tests for Level 2...)
3 Test questions
There is problem when open tests from Level 2 and so on. Inside should be from related Level, but instead there will be tests from Level 1, then Level 2 and so on.
For example below I hardcoded: String selection = "quiz_list_id" + " = ? " + " AND " + "LevelID" + " = 2";.
So when I open Level 2 I see right number of Tests, but first 5 will be empty and from 6 to 10 I have tests for Level 2 from 1 to 4.
I understand that the problem is somehow related to that my Level 2 first Test has id 6 and first 5 are taken by Tests for Level 1.
How can I get those tests to start from beginning? Why previous Level tests are counted and therefore shift next Levels' Tests?
DBHelper.java
...
public ArrayList<Question> getNLevelQuestions(int quizListID) {
ArrayList<Question> questionList = new ArrayList<>();
db = getReadableDatabase();
String table = QuestionsTable.TABLE_NAME + " JOIN " + QuizListTable.TABLE_NAME +
" ON " + QuizListTable.QUIZ_ID + " = " + QuestionsTable.COLUMN_QUIZ_LIST_ID;
//String selection = QuestionsTable.COLUMN_QUIZ_LIST_ID + " = ? ";
//Below hardcoded version of string selection
String selection = "quiz_list_id" + " = ? " + " AND " + "LevelID" + " = 2";
String selectionArgs = new String{String.valueOf(quizListID)};
Cursor c = db.query(table,
null,
selection,
selectionArgs,
null,
null,
null
);
if (c.moveToFirst()) {
do {
Question question = new Question();
question.setId(c.getInt(c.getColumnIndex(QuestionsTable._ID)));
question.setQuestion(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_QUESTION)));
question.setOption1(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION1)));
question.setOption2(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION2)));
question.setOption3(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION3)));
question.setOption4(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION4)));
question.setAnswerNB(c.getInt(c.getColumnIndex(QuestionsTable.COLUMN_ANSWER_NB)));
question.setListTest(c.getInt(c.getColumnIndex(QuestionsTable.COLUMN_QUIZ_LIST_ID)));
questionList.add(question);
} while (c.moveToNext());
}
c.close();
return questionList;
}
}
QuizContractor.java
public final class QuizContract {
private QuizContract() {
}
public static class JLPTLevelsTable implements BaseColumns{
public static final String TABLE_NAME = "test_level";
public static final String COLUMN_NAME = "LevelName";
public static final String COLUMN_JLPTLevel_ID = "LevelID";
}
public static class QuizListTable implements BaseColumns{
public static final String TABLE_NAME = "quiz_list";
public static final String COLUMN_NAME = "name";
public static final String COLUMN_JLPTLevel_ID = "LevelID";
public static final String QUIZ_ID ="quiz_id";
}
public static class QuestionsTable implements BaseColumns {
public static final String TABLE_NAME = "quiz_questions";
public static final String COLUMN_QUESTION = "question";
public static final String COLUMN_OPTION1 = "option1";
public static final String COLUMN_OPTION2 = "option2";
public static final String COLUMN_OPTION3 = "option3";
public static final String COLUMN_OPTION4 = "option4";
public static final String COLUMN_ANSWER_NB = "answer_nb";
public static final String COLUMN_QUIZ_LIST_ID = "quiz_list_id";
}
}
I
sqlite arraylist android-sqlite
add a comment |
My database consist of 3 tables.
1 Levels (1 Level, 2 Level, 3 Level)
2 Test groups (5 Tests for Level 1, 10 Tests for Level 2...)
3 Test questions
There is problem when open tests from Level 2 and so on. Inside should be from related Level, but instead there will be tests from Level 1, then Level 2 and so on.
For example below I hardcoded: String selection = "quiz_list_id" + " = ? " + " AND " + "LevelID" + " = 2";.
So when I open Level 2 I see right number of Tests, but first 5 will be empty and from 6 to 10 I have tests for Level 2 from 1 to 4.
I understand that the problem is somehow related to that my Level 2 first Test has id 6 and first 5 are taken by Tests for Level 1.
How can I get those tests to start from beginning? Why previous Level tests are counted and therefore shift next Levels' Tests?
DBHelper.java
...
public ArrayList<Question> getNLevelQuestions(int quizListID) {
ArrayList<Question> questionList = new ArrayList<>();
db = getReadableDatabase();
String table = QuestionsTable.TABLE_NAME + " JOIN " + QuizListTable.TABLE_NAME +
" ON " + QuizListTable.QUIZ_ID + " = " + QuestionsTable.COLUMN_QUIZ_LIST_ID;
//String selection = QuestionsTable.COLUMN_QUIZ_LIST_ID + " = ? ";
//Below hardcoded version of string selection
String selection = "quiz_list_id" + " = ? " + " AND " + "LevelID" + " = 2";
String selectionArgs = new String{String.valueOf(quizListID)};
Cursor c = db.query(table,
null,
selection,
selectionArgs,
null,
null,
null
);
if (c.moveToFirst()) {
do {
Question question = new Question();
question.setId(c.getInt(c.getColumnIndex(QuestionsTable._ID)));
question.setQuestion(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_QUESTION)));
question.setOption1(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION1)));
question.setOption2(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION2)));
question.setOption3(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION3)));
question.setOption4(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION4)));
question.setAnswerNB(c.getInt(c.getColumnIndex(QuestionsTable.COLUMN_ANSWER_NB)));
question.setListTest(c.getInt(c.getColumnIndex(QuestionsTable.COLUMN_QUIZ_LIST_ID)));
questionList.add(question);
} while (c.moveToNext());
}
c.close();
return questionList;
}
}
QuizContractor.java
public final class QuizContract {
private QuizContract() {
}
public static class JLPTLevelsTable implements BaseColumns{
public static final String TABLE_NAME = "test_level";
public static final String COLUMN_NAME = "LevelName";
public static final String COLUMN_JLPTLevel_ID = "LevelID";
}
public static class QuizListTable implements BaseColumns{
public static final String TABLE_NAME = "quiz_list";
public static final String COLUMN_NAME = "name";
public static final String COLUMN_JLPTLevel_ID = "LevelID";
public static final String QUIZ_ID ="quiz_id";
}
public static class QuestionsTable implements BaseColumns {
public static final String TABLE_NAME = "quiz_questions";
public static final String COLUMN_QUESTION = "question";
public static final String COLUMN_OPTION1 = "option1";
public static final String COLUMN_OPTION2 = "option2";
public static final String COLUMN_OPTION3 = "option3";
public static final String COLUMN_OPTION4 = "option4";
public static final String COLUMN_ANSWER_NB = "answer_nb";
public static final String COLUMN_QUIZ_LIST_ID = "quiz_list_id";
}
}
I
sqlite arraylist android-sqlite
My database consist of 3 tables.
1 Levels (1 Level, 2 Level, 3 Level)
2 Test groups (5 Tests for Level 1, 10 Tests for Level 2...)
3 Test questions
There is problem when open tests from Level 2 and so on. Inside should be from related Level, but instead there will be tests from Level 1, then Level 2 and so on.
For example below I hardcoded: String selection = "quiz_list_id" + " = ? " + " AND " + "LevelID" + " = 2";.
So when I open Level 2 I see right number of Tests, but first 5 will be empty and from 6 to 10 I have tests for Level 2 from 1 to 4.
I understand that the problem is somehow related to that my Level 2 first Test has id 6 and first 5 are taken by Tests for Level 1.
How can I get those tests to start from beginning? Why previous Level tests are counted and therefore shift next Levels' Tests?
DBHelper.java
...
public ArrayList<Question> getNLevelQuestions(int quizListID) {
ArrayList<Question> questionList = new ArrayList<>();
db = getReadableDatabase();
String table = QuestionsTable.TABLE_NAME + " JOIN " + QuizListTable.TABLE_NAME +
" ON " + QuizListTable.QUIZ_ID + " = " + QuestionsTable.COLUMN_QUIZ_LIST_ID;
//String selection = QuestionsTable.COLUMN_QUIZ_LIST_ID + " = ? ";
//Below hardcoded version of string selection
String selection = "quiz_list_id" + " = ? " + " AND " + "LevelID" + " = 2";
String selectionArgs = new String{String.valueOf(quizListID)};
Cursor c = db.query(table,
null,
selection,
selectionArgs,
null,
null,
null
);
if (c.moveToFirst()) {
do {
Question question = new Question();
question.setId(c.getInt(c.getColumnIndex(QuestionsTable._ID)));
question.setQuestion(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_QUESTION)));
question.setOption1(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION1)));
question.setOption2(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION2)));
question.setOption3(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION3)));
question.setOption4(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION4)));
question.setAnswerNB(c.getInt(c.getColumnIndex(QuestionsTable.COLUMN_ANSWER_NB)));
question.setListTest(c.getInt(c.getColumnIndex(QuestionsTable.COLUMN_QUIZ_LIST_ID)));
questionList.add(question);
} while (c.moveToNext());
}
c.close();
return questionList;
}
}
QuizContractor.java
public final class QuizContract {
private QuizContract() {
}
public static class JLPTLevelsTable implements BaseColumns{
public static final String TABLE_NAME = "test_level";
public static final String COLUMN_NAME = "LevelName";
public static final String COLUMN_JLPTLevel_ID = "LevelID";
}
public static class QuizListTable implements BaseColumns{
public static final String TABLE_NAME = "quiz_list";
public static final String COLUMN_NAME = "name";
public static final String COLUMN_JLPTLevel_ID = "LevelID";
public static final String QUIZ_ID ="quiz_id";
}
public static class QuestionsTable implements BaseColumns {
public static final String TABLE_NAME = "quiz_questions";
public static final String COLUMN_QUESTION = "question";
public static final String COLUMN_OPTION1 = "option1";
public static final String COLUMN_OPTION2 = "option2";
public static final String COLUMN_OPTION3 = "option3";
public static final String COLUMN_OPTION4 = "option4";
public static final String COLUMN_ANSWER_NB = "answer_nb";
public static final String COLUMN_QUIZ_LIST_ID = "quiz_list_id";
}
}
I
sqlite arraylist android-sqlite
sqlite arraylist android-sqlite
asked Jan 1 at 13:44
Alex KAlex K
388
388
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
How can I get those tests to start from beginning? Why previous Level tests are counted and therefore shift next Levels' Tests?
Effectively there is no beginning. You are basically misusing/misconceiving the concept of id's and how they should be used.
An id should be considered only as a means of uniquely identifiying a row. Considering it to be a specific value, such as 1,2,3... will only cause issues.
Assuming that what you want is to display the extracted questions along the lines of :-
- What bird laid the Golden egg?
- Cuckoo
- Chicken
- Goose
- Sparrow
- Who killed the Sparrow?
- The robin.
- Another sparrow.
- The finch.
- The eagle.
and you are getting :-
- What bird laid the Golden egg?
- Cuckoo
- Chicken
- Goose
- Sparrow
- Who killed the Sparrow?
- The robin.
- Another sparrow.
- The finch.
- The eagle.
And as such want 5 to be 1 and 6 to be 2 then:-
Instead of using the id you could use a sequence number set elsewhere.
As an example you could add another variable/member to the Question object say int sequence
along with a setter such as setSequence(int sequence)
and a getter such as int getSqeuence()
and then use :-
if (c.moveToFirst()) {
do {
Question question = new Question();
question.setSequence(csr.getPosition() + 1); //<<<<<<<<<< ADDED
question.setId(c.getInt(c.getColumnIndex(QuestionsTable._ID)));
question.setQuestion(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_QUESTION)));
question.setOption1(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION1)));
question.setOption2(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION2)));
question.setOption3(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION3)));
question.setOption4(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION4)));
question.setAnswerNB(c.getInt(c.getColumnIndex(QuestionsTable.COLUMN_ANSWER_NB)));
question.setListTest(c.getInt(c.getColumnIndex(QuestionsTable.COLUMN_QUIZ_LIST_ID)));
questionList.add(question);
} while (c.moveToNext());
}
And then instead of using the getter getId() use getSequence().
But when I am debugging I have quizListID: 1 already at this point : String selectionArgs = new String{String.valueOf(quizListID)}; I need to get my quizListID: 6 there. So problem happens earlier.
– Alex K
Jan 13 at 5:19
What if it were 9999 or 53995952? As long as you believe that the id has any value other than for identifying a row programatically you will likely have issues.
– MikeT
Jan 13 at 5:29
I understand, but modifying Question object and using getPosition() inside advised place brings no positive or negative changes at all.
– Alex K
Jan 13 at 5:51
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53995952%2fsqlite-load-items-from-previous-group%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
How can I get those tests to start from beginning? Why previous Level tests are counted and therefore shift next Levels' Tests?
Effectively there is no beginning. You are basically misusing/misconceiving the concept of id's and how they should be used.
An id should be considered only as a means of uniquely identifiying a row. Considering it to be a specific value, such as 1,2,3... will only cause issues.
Assuming that what you want is to display the extracted questions along the lines of :-
- What bird laid the Golden egg?
- Cuckoo
- Chicken
- Goose
- Sparrow
- Who killed the Sparrow?
- The robin.
- Another sparrow.
- The finch.
- The eagle.
and you are getting :-
- What bird laid the Golden egg?
- Cuckoo
- Chicken
- Goose
- Sparrow
- Who killed the Sparrow?
- The robin.
- Another sparrow.
- The finch.
- The eagle.
And as such want 5 to be 1 and 6 to be 2 then:-
Instead of using the id you could use a sequence number set elsewhere.
As an example you could add another variable/member to the Question object say int sequence
along with a setter such as setSequence(int sequence)
and a getter such as int getSqeuence()
and then use :-
if (c.moveToFirst()) {
do {
Question question = new Question();
question.setSequence(csr.getPosition() + 1); //<<<<<<<<<< ADDED
question.setId(c.getInt(c.getColumnIndex(QuestionsTable._ID)));
question.setQuestion(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_QUESTION)));
question.setOption1(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION1)));
question.setOption2(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION2)));
question.setOption3(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION3)));
question.setOption4(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION4)));
question.setAnswerNB(c.getInt(c.getColumnIndex(QuestionsTable.COLUMN_ANSWER_NB)));
question.setListTest(c.getInt(c.getColumnIndex(QuestionsTable.COLUMN_QUIZ_LIST_ID)));
questionList.add(question);
} while (c.moveToNext());
}
And then instead of using the getter getId() use getSequence().
But when I am debugging I have quizListID: 1 already at this point : String selectionArgs = new String{String.valueOf(quizListID)}; I need to get my quizListID: 6 there. So problem happens earlier.
– Alex K
Jan 13 at 5:19
What if it were 9999 or 53995952? As long as you believe that the id has any value other than for identifying a row programatically you will likely have issues.
– MikeT
Jan 13 at 5:29
I understand, but modifying Question object and using getPosition() inside advised place brings no positive or negative changes at all.
– Alex K
Jan 13 at 5:51
add a comment |
How can I get those tests to start from beginning? Why previous Level tests are counted and therefore shift next Levels' Tests?
Effectively there is no beginning. You are basically misusing/misconceiving the concept of id's and how they should be used.
An id should be considered only as a means of uniquely identifiying a row. Considering it to be a specific value, such as 1,2,3... will only cause issues.
Assuming that what you want is to display the extracted questions along the lines of :-
- What bird laid the Golden egg?
- Cuckoo
- Chicken
- Goose
- Sparrow
- Who killed the Sparrow?
- The robin.
- Another sparrow.
- The finch.
- The eagle.
and you are getting :-
- What bird laid the Golden egg?
- Cuckoo
- Chicken
- Goose
- Sparrow
- Who killed the Sparrow?
- The robin.
- Another sparrow.
- The finch.
- The eagle.
And as such want 5 to be 1 and 6 to be 2 then:-
Instead of using the id you could use a sequence number set elsewhere.
As an example you could add another variable/member to the Question object say int sequence
along with a setter such as setSequence(int sequence)
and a getter such as int getSqeuence()
and then use :-
if (c.moveToFirst()) {
do {
Question question = new Question();
question.setSequence(csr.getPosition() + 1); //<<<<<<<<<< ADDED
question.setId(c.getInt(c.getColumnIndex(QuestionsTable._ID)));
question.setQuestion(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_QUESTION)));
question.setOption1(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION1)));
question.setOption2(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION2)));
question.setOption3(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION3)));
question.setOption4(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION4)));
question.setAnswerNB(c.getInt(c.getColumnIndex(QuestionsTable.COLUMN_ANSWER_NB)));
question.setListTest(c.getInt(c.getColumnIndex(QuestionsTable.COLUMN_QUIZ_LIST_ID)));
questionList.add(question);
} while (c.moveToNext());
}
And then instead of using the getter getId() use getSequence().
But when I am debugging I have quizListID: 1 already at this point : String selectionArgs = new String{String.valueOf(quizListID)}; I need to get my quizListID: 6 there. So problem happens earlier.
– Alex K
Jan 13 at 5:19
What if it were 9999 or 53995952? As long as you believe that the id has any value other than for identifying a row programatically you will likely have issues.
– MikeT
Jan 13 at 5:29
I understand, but modifying Question object and using getPosition() inside advised place brings no positive or negative changes at all.
– Alex K
Jan 13 at 5:51
add a comment |
How can I get those tests to start from beginning? Why previous Level tests are counted and therefore shift next Levels' Tests?
Effectively there is no beginning. You are basically misusing/misconceiving the concept of id's and how they should be used.
An id should be considered only as a means of uniquely identifiying a row. Considering it to be a specific value, such as 1,2,3... will only cause issues.
Assuming that what you want is to display the extracted questions along the lines of :-
- What bird laid the Golden egg?
- Cuckoo
- Chicken
- Goose
- Sparrow
- Who killed the Sparrow?
- The robin.
- Another sparrow.
- The finch.
- The eagle.
and you are getting :-
- What bird laid the Golden egg?
- Cuckoo
- Chicken
- Goose
- Sparrow
- Who killed the Sparrow?
- The robin.
- Another sparrow.
- The finch.
- The eagle.
And as such want 5 to be 1 and 6 to be 2 then:-
Instead of using the id you could use a sequence number set elsewhere.
As an example you could add another variable/member to the Question object say int sequence
along with a setter such as setSequence(int sequence)
and a getter such as int getSqeuence()
and then use :-
if (c.moveToFirst()) {
do {
Question question = new Question();
question.setSequence(csr.getPosition() + 1); //<<<<<<<<<< ADDED
question.setId(c.getInt(c.getColumnIndex(QuestionsTable._ID)));
question.setQuestion(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_QUESTION)));
question.setOption1(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION1)));
question.setOption2(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION2)));
question.setOption3(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION3)));
question.setOption4(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION4)));
question.setAnswerNB(c.getInt(c.getColumnIndex(QuestionsTable.COLUMN_ANSWER_NB)));
question.setListTest(c.getInt(c.getColumnIndex(QuestionsTable.COLUMN_QUIZ_LIST_ID)));
questionList.add(question);
} while (c.moveToNext());
}
And then instead of using the getter getId() use getSequence().
How can I get those tests to start from beginning? Why previous Level tests are counted and therefore shift next Levels' Tests?
Effectively there is no beginning. You are basically misusing/misconceiving the concept of id's and how they should be used.
An id should be considered only as a means of uniquely identifiying a row. Considering it to be a specific value, such as 1,2,3... will only cause issues.
Assuming that what you want is to display the extracted questions along the lines of :-
- What bird laid the Golden egg?
- Cuckoo
- Chicken
- Goose
- Sparrow
- Who killed the Sparrow?
- The robin.
- Another sparrow.
- The finch.
- The eagle.
and you are getting :-
- What bird laid the Golden egg?
- Cuckoo
- Chicken
- Goose
- Sparrow
- Who killed the Sparrow?
- The robin.
- Another sparrow.
- The finch.
- The eagle.
And as such want 5 to be 1 and 6 to be 2 then:-
Instead of using the id you could use a sequence number set elsewhere.
As an example you could add another variable/member to the Question object say int sequence
along with a setter such as setSequence(int sequence)
and a getter such as int getSqeuence()
and then use :-
if (c.moveToFirst()) {
do {
Question question = new Question();
question.setSequence(csr.getPosition() + 1); //<<<<<<<<<< ADDED
question.setId(c.getInt(c.getColumnIndex(QuestionsTable._ID)));
question.setQuestion(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_QUESTION)));
question.setOption1(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION1)));
question.setOption2(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION2)));
question.setOption3(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION3)));
question.setOption4(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION4)));
question.setAnswerNB(c.getInt(c.getColumnIndex(QuestionsTable.COLUMN_ANSWER_NB)));
question.setListTest(c.getInt(c.getColumnIndex(QuestionsTable.COLUMN_QUIZ_LIST_ID)));
questionList.add(question);
} while (c.moveToNext());
}
And then instead of using the getter getId() use getSequence().
answered Jan 1 at 23:37
MikeTMikeT
16.7k112642
16.7k112642
But when I am debugging I have quizListID: 1 already at this point : String selectionArgs = new String{String.valueOf(quizListID)}; I need to get my quizListID: 6 there. So problem happens earlier.
– Alex K
Jan 13 at 5:19
What if it were 9999 or 53995952? As long as you believe that the id has any value other than for identifying a row programatically you will likely have issues.
– MikeT
Jan 13 at 5:29
I understand, but modifying Question object and using getPosition() inside advised place brings no positive or negative changes at all.
– Alex K
Jan 13 at 5:51
add a comment |
But when I am debugging I have quizListID: 1 already at this point : String selectionArgs = new String{String.valueOf(quizListID)}; I need to get my quizListID: 6 there. So problem happens earlier.
– Alex K
Jan 13 at 5:19
What if it were 9999 or 53995952? As long as you believe that the id has any value other than for identifying a row programatically you will likely have issues.
– MikeT
Jan 13 at 5:29
I understand, but modifying Question object and using getPosition() inside advised place brings no positive or negative changes at all.
– Alex K
Jan 13 at 5:51
But when I am debugging I have quizListID: 1 already at this point : String selectionArgs = new String{String.valueOf(quizListID)}; I need to get my quizListID: 6 there. So problem happens earlier.
– Alex K
Jan 13 at 5:19
But when I am debugging I have quizListID: 1 already at this point : String selectionArgs = new String{String.valueOf(quizListID)}; I need to get my quizListID: 6 there. So problem happens earlier.
– Alex K
Jan 13 at 5:19
What if it were 9999 or 53995952? As long as you believe that the id has any value other than for identifying a row programatically you will likely have issues.
– MikeT
Jan 13 at 5:29
What if it were 9999 or 53995952? As long as you believe that the id has any value other than for identifying a row programatically you will likely have issues.
– MikeT
Jan 13 at 5:29
I understand, but modifying Question object and using getPosition() inside advised place brings no positive or negative changes at all.
– Alex K
Jan 13 at 5:51
I understand, but modifying Question object and using getPosition() inside advised place brings no positive or negative changes at all.
– Alex K
Jan 13 at 5:51
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53995952%2fsqlite-load-items-from-previous-group%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown