最近要实现一个像新浪微博的点击首页实现当前页面的刷新。在网上看了好多文章,最终还是在Google上的http://stackoverflow.com/questions/5487770/get-notified-when-current-tab-is-selected-again得到了启发,终于能够实现此功能,现在就把实现此功能的做法。。
原文是这样说的。。。(此部分代码是Google上的。也就是http://stackoverflow.com/questions/5487770/get-notified-when-current-tab-is-selected-again)
I implemented a TabActivity
which implements the OnTabChangeListener
. The activity will be notified on tab changes (onTabChanged(String tabId)
).
Is it also possible to get notified if the user selects the current tab again?
I would like to use this event to perform a "refresh" of the current tab content instead of providing a refresh button on the tab or in the options menu.
That's the way I finally solved the problem - solution hint was in MisterSquonk answer.
(1) Define a OnTabReselectListener which must be implemented by an activity which represents a tab content and which will be notified on reselect events.
/**
* Interface definition for a callback to be invoked when a current selected tab
* in a TabHost is selected again.
*/
public interface OnTabReselectListener {
/**
* Called when a current visible tab is selected again. Will not be invoked
* on tab changes.
*/
void onTabReselect();
}
(2) setOnTouchListener for each tabWidget child in onCreate() of the TabActivity (from MisterSquonk's answer)
for (