我如何测试/监听选项卡更改?
基本上是上面的问题,您不需要阅读下面的内容,只需阅读有关我想如何使用它的附加信息。
我有一个带有两个选项卡的活动(扩展选项卡活动)。我的选项卡没有不同的意图,它们都填充在同一个活动中。在每一个中,我都有一个从数据库填充的列表。
这两个选项卡是“收入”和“结果”,我一直在尝试对其进行设置,以便根据打开的选项卡运行不同的查询并显示不同的列表。
显示了正确的数据,但无论第一个打开的选项卡都是唯一包含任何内容的选项卡,我意识到这是因为它没有重新查询数据库(我的 getBudgetAmount 方法)并在选项卡打开时显示列表(showBudgetCategories 方法)更改并认为我必须测试该更改,但我还没有找到可行的方法。然后我想也许有一个我可以使用的侦听器?如果有人能指出我正确的方法,我将非常感激!
这是我的活动:
编辑,格式一直很有趣,您会发现这里更容易阅读-http ://codeviewer.org/view/code:1501
Basically the question above, you don't need to read the lot below, just additional info on how i want to use it.
I Have an activity (which extends tab activity) with two tabs. My tabs don't have different intentss, they're both filled within the same activity. Within each of these i have a list i'm filling from a Database.
The two tabs are "income" and "outcome" and I've been trying to set it up so that depending on the open tab a different query will be run and a different list is displayed.
The right data is displayed but whatever tab opens first is the only one that has anything in it, i realised this was because it wasn't re-querying the database (my getBudgetAmount method) and showing the list (showBudgetCategories method) when the tab changed and figured i'd have to test for that change but i haven't found a way to do that yet that works.. then i thought maybe there's a listener i could use instead? If anyone could point me the right way i'd really appreciate it!
Here's my activity:
EDIT, formatting keeps going funny, you'll find it easier to read here-http://codeviewer.org/view/code:1501
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让您的 Budget 类实现
OnTabChangeListener
,然后在 onCreate() 方法中添加以下行:
然后让您的 Budget 类实现
onTabChanged
:Have your Budget class implement
OnTabChangeListener
, then in the onCreate() method,add this line:
Then have your Budget class implement
onTabChanged
: