Search code examples
androidsetcontentview

setContentView is unidentified


The setContentView is underscored with red squiggle. I cleaned the workspace but the same error remains. Any suggestions?

Code:

public class SensorsTest01 extends Fragment implements OnTabChangeListener {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_tab_bar);
}
@Override
public void onTabChanged(String tabId) {
    // TODO Auto-generated method stub

}

}


Solution

  • setContentView() should not be used instead we have to create a view in onCreateView() of the Fragment Method

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_detail,
            container, false);
        return view;
      }