android - Insertion to SQLiteDatabase -
i wrote code:
// currentfriendstable // --------------------- //| _id | email | uname | // --------------------- // ffriend class class ffriend { string email, uname; // getter , setter } // add single friend database public long addfriend(ffriend friend) { contentvalues values = new contentvalues(); values.put(currentfriendstable.column_email, friend.getemail()); values.put(currentfriendstable.column_uname, friend.getname()); return database.insert(currentfriendstable.table_name, null, values); } // add list of friends database public void addlistoffriends(list<ffriend> listoffriend){ int lenghoflist = listoffriend.size(); (ffriend friend : listoffriend) addfriend(friend); }
i have 2 question here:
when add values table using
database.insert()
function, adding _id automatically ? (i defined column _id primary key autoincrement)is scenario of calling
addfriend(ffriend friend)
function inaddlistoffriends(list<ffriend> listoffriend)
use of may change ?
1) primary key automatically added if define key as:
primary key autoincrement
2) think good. (as suggested here way looping)
just suggestion: not use internal getter , setter in android. use if need or set value outside of target class (reference)
Comments
Post a Comment