android 点击tab页实现当前页面的刷新

本文介绍了如何在Android中实现在点击Tab时刷新当前页面,借鉴了StackOverflow上的解决方案,通过定义一个`OnTabReselectListener`接口并在TabActivity中监听Tab触摸事件,当用户再次选择当前Tab时触发刷新操作。在具体实现中,通过`getTabHost().getCurrentView()`获取当前选中的Tab,并检查其上下文是否实现了监听器,从而调用`onTabReselect()`方法进行刷新。
摘要由CSDN通过智能技术生成

最近要实现一个像新浪微博的点击首页实现当前页面的刷新。在网上看了好多文章,最终还是在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 (
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值