安卓的viewDidLoad和viewDidAppear相当于 [英] Android's viewDidLoad and viewDidAppear equivalent

查看:312
本文介绍了安卓的viewDidLoad和viewDidAppear相当于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android的是否有一个相当于可可的viewDidLoad和viewDidAppear功能?

Does Android have an equivalent to Cocoa's viewDidLoad and viewDidAppear functions?

如果没有,那么我将如何去约一个视图时,会出现执行操作?我的应用程序是一个标签式的应用程序,其中的标签之一是论坛的主题列表。我想话题列表视图每次出现时被刷新。就是这样一个可能的事情在Android的?

If not, then how would I go about performing an action when a View appears? My app is a tabbed application, in which one of the tabs is a list of forum topics. I would like the topic list to be refreshed every time the view appears. Is such a thing possible in Android?

推荐答案

Activity类具有的onCreate和onResume方法是pretty的analagous到viewDidLoad中和viewDidAppear。

The Activity class has onCreate and onResume methods that are pretty analagous to viewDidLoad and viewDidAppear.

Activity.onResume

修改

要加入到这一点,因为有些人提到的评论认为,鉴于树还没有在这些回调完全可用,还有就是你可以听,如果你需要先访问视图层次的ViewTreeObserver。下面是如何使用的ViewTreeObserver实现这一目标的样本。

To add to this, since some have mentioned in the comments that the view tree is not yet fully available during these callbacks, there is the ViewTreeObserver that you can listen to if you need first access to the view hierarchy. Here is a sample of how you can use the ViewTreeObserver to achieve this.

    View someView = findViewById(R.id.someView);
    final ViewTreeObserver obs = someView.getViewTreeObserver();
    obs.addOnPreDrawListener(new OnPreDrawListener() {

        public boolean onPreDraw() {
            obs.removeOnPreDrawListener(this);
            doMyCustomLogic();
            return true;
        }
    });

这篇关于安卓的viewDidLoad和viewDidAppear相当于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆