android - Fragment accessing other java class -


i have been searching internet, not correct answer need. new android, please provide detailed answer.

i have fragment gets data user, ex: name, occupation etc. every single time data, store using gson sharedpreferences. based on searches, need construct regular java user class , pass object (android - save object sharedpreferences , anywhere in app).

  1. so question have is, can fragments access other regular java class functions?

    class userfragment extends fragment {  // data edittext  user newuser = new user("tom"); newuser.setoccupation("programmer");  //etc  } 
  2. can fragment instantiate class , set variables?

  3. if yes 1 , 2, add user class java file, same file fragment implementation of folder , include it?

i provided user example, generically know answer 1 , 2.

thanks

  1. yes fragment object can instantiate class object.
  2. yes can set variables , call functions on object.
  3. entirely you. if class small , local fragment class, can create inside fragment class. if want accessible elsewhere, or make more modular, can create in different package name or same.

Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -