我创建了一个扩展Navigation
的课程Fragment
。当我使用onCreate()
方法时,它错误地说onCreate()
类的方法与onCreate()
android.support.v4.app.Fragment
方法冲突。
package com.beacons.railwayaid.tablayoutapp;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.customlbs.library.IndoorsFactory;
import com.customlbs.surface.library.IndoorsSurfaceFactory;
import com.customlbs.surface.library.IndoorsSurfaceFragment;
public class Navigation extends Fragment {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
IndoorsFactory.Builder indoorsBuilder = new IndoorsFactory.Builder();
IndoorsSurfaceFactory.Builder surfaceBuilder = new IndoorsSurfaceFactory.Builder();
indoorsBuilder.setContext(getContext());
indoorsBuilder.setApiKey("69af5e85-007a-4df5-8715-d1c2c22e206f");
indoorsBuilder.setBuildingId((long) 979231679);
surfaceBuilder.setIndoorsBuilder(indoorsBuilder);
IndoorsSurfaceFragment indoorsFragment = surfaceBuilder.build();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.add(android.R.id.content, indoorsFragment, "indoors");
transaction.commit();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.tab2_railway_navigation, container, false);
return rootView;
}
}
答案 0 :(得分:1)
更改:
@Override
protected void onCreate(Bundle savedInstanceState) {
...
}
为:
@Override
public void onCreate(Bundle savedInstanceState) {
...
}
答案 1 :(得分:0)
尝试将代码移动到onActivityCreated
方法,如下所示:
public class Navigation extends Fragment {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.tab2_railway_navigation, container, false);
return rootView;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
IndoorsFactory.Builder indoorsBuilder = new IndoorsFactory.Builder();
IndoorsSurfaceFactory.Builder surfaceBuilder = new IndoorsSurfaceFactory.Builder();
indoorsBuilder.setContext(getContext());
indoorsBuilder.setApiKey("69af5e85-007a-4df5-8715-d1c2c22e206f");
indoorsBuilder.setBuildingId((long) 979231679);
surfaceBuilder.setIndoorsBuilder(indoorsBuilder);
IndoorsSurfaceFragment indoorsFragment = surfaceBuilder.build();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.add(android.R.id.content, indoorsFragment, "indoors");
transaction.commit();
}
}