mahmoud mahmoud - 9 months ago 36
Android Question

How to use findViewById in onCreate() method in Service class?

When I used

onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
, the problem is that
oncreateview
can't exist in
Service
class.

public class FloatingViewService extends Service{
CircleMenu circleMenu;
public FloatingViewService() {
}

@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public void onCreate() {
super.onCreate();
//Inflate the floating view layout we created
mFloatingView = LayoutInflater
.from(this)
.inflate(R.layout.layout_floating_widget, null);
circleMenu = (CircleMenu) findViewById(R.id.circle_menu);
}

Answer Source

try to change the last line to: circleMenu = (CircleMenu) mFloatingView.findViewById(R.id.circle_menu);

hope it will help :)