如何在Service类的onCreate()方法中使用findViewById?

时间:2017-03-11 21:28:14

标签: java android

当我使用onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)时,问题是oncreateview类中不存在Service

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);
}

1 个答案:

答案 0 :(得分:1)

尝试将最后一行更改为:

circleMenu = (CircleMenu) mFloatingView.findViewById(R.id.circle_menu);