1

I have an ExpandableListView with a custom adapter (lets say in class A), and I need to call setListAdapter(mAdapter) from another class (class B), from a Service specifically.

  mAdapter = new Refeicao.MyExpandableListAdapter();
  setListAdapter(Refeicao.mAdapter);

From similar questions in stackoverflow I tried some solutions, such as:

-1 putting that code into a static method in Class A in order to call it from B - but got the non-static method reference "error"

-2 View listView = getActivity().findViewById(R.id.list); - don't work I suppose because the Service is not an activity

-3
The method setListAdapter(ExpandableListAdapter) is undefined for the type

static ExpandableListView lv;
lv = (ExpandableListView) findViewById(android.R.id.list);

and then

 mAdapter = new A.MyExpandableListAdapter();
                            A.lv.setListAdapter(mAdapter);

I get: the method setListAdapter(ExpandableListAdapter) is undefined for the type ExpandableListView.

Anyway, there's any way to solve my problem?

Zaz Gmy
  • 4,236
  • 3
  • 19
  • 30
Tiago
  • 1,116
  • 5
  • 25
  • 39
  • 1
    You're looking at communicating between a `Service` and an `Activity`. If all you want to do is call that method then your best option is to register a `BroadcastReceiver` in your `Activity` and have the `Service` send a broadcast when it's time to set the adapter. Then in the `onReceive` method of the `BroadcastReceiver` from that `Activity` simply set the adapter. Here is a link http://stackoverflow.com/questions/2463175/how-to-have-android-service-communicate-with-activity – user Jun 08 '12 at 11:41

0 Answers0