Calling findViewById() from outside an activity

后端 未结 4 1334
天涯浪人
天涯浪人 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:53

    Activity's context is in fact the Activity class itself. Assuming that this object will live inside only one Activity, it should be safe to pass object of type Activity to it. Otherwise, think about reengineering your Accordion class.

提交回复
热议问题