android - Alternate way to access multiple columns independently from a database? -


my application stores 3 items: "name", "email", "mobile" in database under same table. want access each of them independently display value under respective textviews. access them independently because if access them through 1 single function won't able display values

currently, have write function each column information it.

example "email"

public string getuseremail(string mobile) {          string[] columns = new string[] {user_email};         cursor c = maindatabase.query(reg_info_table, columns, user_mobile_number + "=" + mobile, null, null, null, null);          string result = "";          int email = c.getcolumnindex(user_email);            while(c.movetonext()) {              result = result + c.getstring(email);          }         return result;      } 

so, if need the "name", i'll have write function similar above it.

now, if need access 50 such columns, i'll have make 50 such functions not sound good. there other way can this? can arrays used here?

you should consider creating user class holds data each user. change getallreginfo() return user object. has advantage rest of app accesses users , has no idea data comes from. more expressive write

user user = getallreginfo(); string name = user.getname(); 

rather than

string[] user = getallreginfo(); string name = user[0]; 

in addition, user class can have fields of type rather being forced convert data string.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -