Pass data between classes

前端 未结 2 1011
孤城傲影
孤城傲影 2021-01-26 02:22

I have two classes. 1st class extends AppCompatActivity and has all my data like arraylist, constants... My 2nd class extends BaseAdapter. Now the question is: I need to use som

相关标签:
2条回答
  • 2021-01-26 02:38

    you can pass data in constructor of second class like this:

    YourBaseAdapter adapter = new YourBaseAdapter(YourDataType1 data1, YourDatatype2 data2, ....)

    all you need to do is create matching constructor in YourBaseAdapter

    0 讨论(0)
  • 2021-01-26 02:52

    use setters and getters to set and get the date. Other way can be passing through constructor in case you do not want to change it once it has been constructed which is one aspect of immutability

    0 讨论(0)
提交回复
热议问题