简体   繁体   English

有没有办法以编程方式更改操作栏菜单项的文本并实时更新?

[英]Is there a way to change the text of a actionbar menu item programatically and update in real time?

So I have a fragment activity and swipe-able views and what not. 所以我有一个片段活动和可滑动查看的视图,而没有。 So right now I just want to know... lets say if the user clicks on any of the items in the list then the menu item in the action bar will add 1. 因此,现在我只想知道...可以说,如果用户单击列表中的任何项目,那么操作栏中的菜单项将添加1。

In my action bar I have the item: "Count: " and another blank item that will store the amount of times a user clicks on an item (ID is countHolder) 在我的操作栏中,我有一个项目:“ Count:”和另一个空白项目,该项目将存储用户单击某个项目的次数(ID为countHolder)

So is there a way to have that countHolder update everytime the user clicks on an item and do it in real time? 那么,是否有一种方法可以使每当用户单击某项并实时执行时,countHolder都会更新?

Also how would it be achieveable? 还有怎么实现呢? I know it would have to be in my onClickListener but I dont know how I would pass that variable around. 我知道它必须在我的onClickListener中,但我不知道如何传递该变量。

从点击事件中,您可以尝试:

getActionBar().setTitle("Count: " + countHolder);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM