How to use java classes within one activity?

后端 未结 4 701
一生所求
一生所求 2021-01-21 17:16

How can you use a java class within one activity, by that I mean is having different components of that activity spread out in a bunch of java classes. I\'m a little new to andr

4条回答
  •  庸人自扰
    2021-01-21 17:48

    You can use your "something" class in the mainactivity.

    first initialize "Something" class in the main activity by

    Something s = new Something(MainActivity.this);
    

    Than you can use every method of that class in your main Activity.Just as you wanted,like this

    s.add.setonclicklistener(...
    

    or

    s.click();
    //Just use like this.
    

提交回复
热议问题