Calling findViewById() from outside an activity

后端 未结 4 1331
天涯浪人
天涯浪人 2021-01-17 12:58

Is there any way to access a layout\'s view from a non-Activity-derived class? I\'m creating an Accordion class and need to access some of the activity\'s UI elements. I\'

4条回答
  •  温柔的废话
    2021-01-17 13:44

    I'm pretty sure you can just pass an activity as a parameter, e.g.

    public void initSouthViews(Activity activity) {
        for (int i = 0; i < southScores_.length; ++i) {
            southScores_[i] = (EditText) activity.findViewById(10);
        }
    }
    

提交回复
热议问题