I work with the MainActivity tool that has access to the UI, I realize in it the ability to determine the data I need, which, once counted, are set in the TextView . The problem is that these methods take up a lot of space and I created the Helper class in which I transferred all these methods, but now I can't access it via findViewById() and even if I pass the TextView in the constructor, I still can't do it set() since it says that set() can only do the activations that created it ... How beautiful it is to solve this problem without transferring resources through the constructor and not using runOnUiThread()

    2 answers 2

    If you mean that you have a set method in the activation class that you want to call from a method of another class, you can transfer it to the Context method, paste it into an activation type and call set

     public void somMethodInSomeClazz(Context ctx, ...) { ActivityMain act = (ActivityMain) ctx; act.set(); } 

    The same Context can be obtained from TextView using the getContext() method and subsequent casting.

     ActivityMain act = (ActivityMain) textView.getContext(); 
    • can you make a short example? Suppose we have 1 TextView and 2 classes (Main and Helper) and according to the condition I have to work with the TextView from Helper (and it does not have access to the UI). Otherwise I didn’t fully understand the idea ... In what class should I define my TextView and where should I transfer the Context. - Aleksey Timoshchenko
    • @AlekseyTimoshchenko, you can do too many ways. Task and uvas formulated very blurry. How do you dislike the idea of ​​transferring a TextView to your class? .. From it you can both context, and activate to get anything. - Yuriy SPb ♦

    And just create a local or global variable of type Helper and call its corresponding methods before setting the TextView value, not an option?