As a new Android programmer, one of the frustrating things it seems is the necessity to convert datatypes between various built-in functions/commands including using SQLITE... unless I am really missing something here. I have spent quite a bit of time on the internet and more specifically here trying to determine the best way to handle some of this.
Here are a couple key ones that I am dealing with right now...
In my activity, I have a SWITCH. The switch uses apparently Boolean for Off/On (no problem) with the setChecked()/isChecked() methods that require or return a Boolean variable (no problem either). I am storing this selection in an SQLITE database which I believe is rather common, but SQLITE doesn't have a Boolean datatype, just INTEGER. So, for both these functions, to go back and forth, we have to convert the integer to boolean and vice versa... and that seems to require several lines of code to do so... each time. Is that correct?
Also in my activity I have a Spinner with an array setup in values/array.xml with the string values. I can use getSelectedItem().toString() to get the string chosen and I can store that in SQLITE text field. But to set that Spinner with the data from the SQLITE, you have to have several lines of code, for each Spinner, to scan the array to find the right value and set the "position". Shouldn't there be a function or method to set the Spinner by value?
Another, as is recommended by almost everyone using SQLITE (and databases in general), an AutoIncrement field is ideal and that is an INTEGER. Functions like SQLiteDatabase.insert returns the inserted record # as a long. So to store that variable and use it for updating purposes, the LONG has to be converted to an INTEGER (which "could" be problematic) and vice versa. Again, is that correct?
I do realize the SQLITE wasn't originally written for Android/Java... but if it is a relative mainstay in that programming, shouldn't there be built-in considerations for these issues... again, unless I am missing something?
So, after spending the better part of night working on some code that was erroring out, basically because of these issues (and a few more), and rewritting a bunch of it hopefully correct, I have made a pretty jumbled mess and am losing track of what variable needs to be what to work.
I probably made this whole posting more confusing because as of right now, I am really getting confused... So, the question is... am I missing something here or is all this normal?
Thanks
Aucun commentaire:
Enregistrer un commentaire