java - 在另一个非activity类中如何调用并操作当前activity界面上的元素?
大家讲道理
大家讲道理 2017-04-18 09:55:57
0
4
475

初学,在尝试自己写。先谢过各位!

大家都回家得很好,已经有思路了也学到了很多,再次感谢。

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(4)
迷茫

If the class activity you mentioned holds an instance, then you can directly pass the instance of the view to it for operation. However, you will usually write a method in the activity to operate the view, and then let other classes call this method, because the instance of the view The creation and destruction are related to the life cycle of the activity, so it is best not to let classes outside the activity directly hold and operate the views in this activity. In addition, be careful to operate the views on the UI thread

Ty80

Non-activity? Is it a fragment? service? Or what? No matter where you update, it's a communication issue between them.
Recommendations:
1. You can use interfaces for communication
2. You can use the EventBar event bus open source library, so that you can learn the use of an open source library

刘奇

You are talking about operating View in a non-Activity class. Currently, most of them adopt the MVP development model and use the interface callback mechanism to operate View. However, MVP has pros and cons. When operating View, MVP must ensure the persistence of View. deal with.

大家讲道理

First of all, you need to know the relationship between your class and this activity. If it is a helper class, then this activity should have an instance of this class. Then you only need to call a corresponding method of this instance. If this class needs To operate a view object or other object in the activity, pass the object as a parameter into the method.
If it is other classes, such as service or broadcast, just learn how to use these components
I hope it will be helpful to you,,

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template