0

This code below works with both a DAO and dBhelper class. I have 3 tables with approx 6 columns for each, but I'm fed up "playing" with the field names for every method (insert, delete and so on..) and would like to replace that code below using a for-loop, browsing both the field names and data to be inserted into the dB.

So the question is :
how to replace such an expression MySQLiteHelper.COLUMN_ID to MySQLiteHelper.columnName sothat I can embed this oneliner into a for-loop.

private String[] allColumns = {
    MySQLiteHelper.COLUMN_level_1,
    MySQLiteHelper.COLUMN_level_2,
    MySQLiteHelper.COLUMN_level_3
};
String[] mydata = myobject.getData();

// Here I would like to use a for-loop for the following lines
values.put(MySQLiteHelper.COLUMN_level_1, mydata[0]);
values.put(MySQLiteHelper.COLUMN_level_2, mydata[1]);
values.put(MySQLiteHelper.COLUMN_level_3, mydata[2]);
1
  • Not quite sure what your asking but I guess what I have is at least semi what you want Commented Jul 1, 2012 at 13:01

1 Answer 1

1
private String[] allColumns = {
    MySQLiteHelper.COLUMN_level_1,
    MySQLiteHelper.COLUMN_level_2,
    MySQLiteHelper.COLUMN_level_3
};

String[] mydata = myobject.getData();

for(int i = 0; i < allColums.length(); i++){
    values.put(allColums[i], mydata[i]);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thx, I'm so ashamed as I was trying to replace constant names.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.