首页 > android > 刷新活动

刷新活动 (Refreshing an Activity)

问题

我创建了一个Activity允许在具有几个按钮(上一个和下一个)的页面之间导航。当用户单击其中一个按钮时,Activity(相同)需要“刷新”。为此,我设置了按钮来拨打电话

onCreate(this);

在他们设置了活动用于分页工作的其他内容之后。

它到目前为止工作,但我想知道是否有更好的方法。在那儿?

解决方法

我修复了这个槽重构:

使用onCreate中执行的代码创建了一个新函数(即布局初始化,数据库访问和信息显示)。新函数由onCreate方法调用(当Activity获取“Create”通知时),并且在任何时候我需要“刷新”Activity的内容(即按下按钮时)。

感谢您的意见。

问题

I created an Activity which allows navigating between pages with a couple of Buttons (Previous and Next). When the user clicks one of the buttons, the Activity (same) needs to be "refreshed". In order to do this, I set up the buttons to make a call to

onCreate(this);

after they set up the other stuff that the activity uses for the paging to work.

And it is working so far, but I'm wondering if there is a better way. Is there?

解决方法

I fixed this trough refactoring:

Created a new function with the code that was being executed in onCreate (i.e. Layout initialization, database access and information display). The new function is called by the onCreate method (when the Activity gets the "Create" notification) and at anytime that I need to "refresh" the contents of the Activity (i.e. when a button is pressed).

Thanks for your comments.

相似信息