There is an activity in which there is a method that updates the data in the ListView .

There are many more methods in this method, these methods also contain some methods and variables. This method is called a number of times in this activation. But it took me one time to call him from another class. You can of course make all methods and public static variables (which was done) and calmly call a method from another class without creating an instance, but this is not correct.


So, the question is: how can I call a method from another class?

  • one
    you'd better give more context, otherwise you are definitely trying to make a crutch. - Vladyslav Matviienko

1 answer 1

No non-static method is non-static , which requires an instance of the class containing it.

In general, you have some strange problem. I am almost sure that what you want to do is perfectly solved with the help of Intent and BroadcastReceiver .

  • There is a class that inherits from ListView. In it, I catch the user's touch. MotionEvent.ACTION_DOWN, MotionEvent.ACTION_UP and so on. If the condition was successful, you must update the list with the Reload method. And he is in another class. - dexter
  • Why not just call notifyDataSetChanged() on the ListView adapter? - falstaf
  • for updating - I clear the list, then send a request to the server, the server returns a response in json format, I parse and drive in the data. - dexter
  • Well, do sendBroadcast() when you need to update the list, and let the Activity in BroadcastReceiver wait for this Intent ', and upon receiving it, accordingly, it updates it. - falstaf
  • Complicate. @dexter, in my opinion, this is ideal for using the Listener pattern - jimpanzer