Search code examples
javaandroidsetterjdevelopergetter

When is getters setters needed in android studio project?


I can generate getters and setters in java program and I know that it is used to access private variables. Besides this How will I be able to decide this, at this point I need to create java class with getters and setters.


Solution

  • Getter and Setter methods are used for encapsulate the data. it means wrapping the data into single unit.

    For example create a ListView with 3 TextView who has different-different value.

    so now the question is how will you send the data to your custom ListView adapter. In this case you have to use a beam(has getter-setter methods) class.

    EDIT:

    Here is another example it will show how to send multiple data by single object from one Activity to another Activity

    https://stackoverflow.com/a/7827593/6676466