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

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -