在类之间传递数据 [英] Pass data between classes

查看:90
本文介绍了在类之间传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两节课。第一类扩展了AppCompatActivity并拥有我的所有数据,如arraylist,常量...
我的第二类扩展了BaseAdapter。
现在的问题是:我需要在第二课中使用第一课的一些数据如何传递数据?我不能使用Intents而且我无法扩展第二类,因为它已经扩展了BaseAdapter。
有什么想法吗?

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 some data from 1st class in my 2nd class how do I pass the data? I can't use Intents and I can't extend the 2nd class because it is already extends BaseAdapter. Any ideas?

推荐答案

使用 setters getters 设置并获取日期。其他方式可以通过构造函数传递,以防你不想在构造后更改它,这是不变性的一个方面

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

这篇关于在类之间传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆