android - How to access SQLite db, created in an Activity, from a Fragment? -


i have local sqlite db created in formactivity.java, so:

db = new sqlitehandler(getapplicationcontext());  string name = user.getstring("name"); string surname = user.getstring("surname"); string title= user.getstring("title");  db.adduser(name, surname, title); 

i have fragment several textfields. wish fill these fields data db created in activity. below:

@override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {         view v = inflater.inflate(r.layout.fragment_first, container, false);          //set inputs fields         inputtitle = (edittext) v.findviewbyid(r.id.titletext);         inputname = (edittext) v.findviewbyid(r.id.foretext);         inputsurname = (edittext) v.findviewbyid(r.id.surnametext);          textview tv = (textview) v.findviewbyid(r.id.tvfragfirst);         tv.settext(getarguments().getstring("msg"));          return v;          // fetching user details sqlite         hashmap<string, string> user = db.getuserdetails();          string name = user.get("name");         string surname = user.get("surname");          // displaying user details on screen         inputname.settext(name);         inputsurname.settext(surname);         inputtitle.settext(title);     } 

my problem @ moment db.getuserdetails(), don't know , cannot find how can access db within fragment. i'm sure it's simple fix set me right here please? thanks.

call method

 hashmap<string, string> user = db.getuserdetails(); 

before return view , create sqlitehandler in fragment

 db = new sqlitehandler(getactivity()); 

final code be.

    // fetching user details sqlite  hashmap<string, string> user = db.getuserdetails();   string name = user.get("name");  string surname = user.get("surname");      // displaying user details on screen  inputname.settext(name);  inputsurname.settext(surname);  inputtitle.settext(title);   return v; 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -