Search code examples
androidandroid-activityadapter

How to call a method from adapter in activity?


I just want to call a method (which is declared in an adapter) from an activity . Is there any possible way to do it?


Solution

  • There are several ways to call a method from adapter in activity : 1. Using your adapter object in activity. You can easily call your adapter method.

    Suppose you have create a method in adapter like see below :

    public ArrayList getSelectedItems() { return selectedList }

    In Activity you have to call this method : yourAdapter = YourAdapter(yourList) yourAdapter.getSelectedItems()

    Simple!!

    1. One Other way is using interface.