How can I declare TextView as global variable to use in other class

前端 未结 4 1890
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-16 05:45

I am a new android dev. I want to use a same TextView in all activity. But, i don\'t know how to declare TextView as global Variable & How can i use thi

4条回答
  •  借酒劲吻你
    2021-01-16 06:21

    Make it a singleton. Or just keep one public static reference.

    public class MyReference {
        public static TextView myTextView = new TextView();
    }
    

    and then you can use it anywhere by calling MyReference.myTextView

提交回复
热议问题