运行应用时缺少课程

时间:2016-04-27 14:16:24

标签: java android android-fragments android-library

我在示例应用中使用自定义Android库。该库有一个片段,必须在app示例的主要活动中使用。

我已经按照步骤在不同的教程中使用它,因为它们都没有100%调整到我的项目。

该片段包含以下代码:

public class MapFragment extends Fragment implements MapView, OnMapReadyCallback {

    private static final float ZOOM_INITIAL = 12;
    private OnFragmentInteractionListener mListener;
    private SupportMapFragment fragment;
    private GoogleMap googleMap;
    private Location initialLocation;
    private WifiSpotsMapPresenter presenter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_wifi_spots_map, container, false);
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        this.googleMap = googleMap;

        centerInLocation(initialLocation);
    }

    private void centerInLocation(Location location) {
        LatLng myLaLn = new LatLng(location.getLatitude(), location.getLongitude());
        CameraPosition camPos = new CameraPosition.Builder().target(myLaLn).zoom(ZOOM_INITIAL).bearing(0).tilt(0).build();
        CameraUpdate camUpd3 = CameraUpdateFactory.newCameraPosition(camPos);
        googleMap.animateCamera(camUpd3);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof OnFragmentInteractionListener) {
            mListener = (OnFragmentInteractionListener) context;
        } else {
            throw new RuntimeException(context.toString()
                    + " must implement OnFragmentInteractionListener");
        }
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        init();
        initmap();
    }

    private void initmap() {
        FragmentManager fm = getChildFragmentManager();
        fragment = (SupportMapFragment) fm.findFragmentById(R.id.map);
        if (fragment == null) {
            fragment = SupportMapFragment.newInstance();
            fm.beginTransaction().replace(R.id.map, fragment).commit();
            fragment.getMapAsync(this);
        }
    }

    private void init() {
        initialLocation = new Location("");
        initialLocation.setLongitude(-3.742735);
        initialLocation.setLatitude(40.474886);

        presenter = new WifiSpotsMapPresenterImpl();
        presenter.setView(this);
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mListener = null;
    }

    public interface OnFragmentInteractionListener {
        void onFragmentInteraction(Uri uri);
    }
}

主要活动:

import example.sdk.ui.map.view.MapFragment;

public class MainActivity extends FragmentActivity implements MapFragment.OnFragmentInteractionListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public void onFragmentInteraction(Uri uri) {

    }
}

在编程时,android studio可以完美地解决依赖关系,它一如既往地添加了导入,我可以完美地使用实现MapFragment.OnFragmentInteractionListener (编程时你不知道红色0错误)。

问题在于我构建/运行它。出现此错误:

Error:(9, 83) error: cannot find symbol class OnFragmentInteractionListener
Error:(17, 5) error: method does not override or implement a method from a supertype

如果它在编程时能够完美地解决课程怎么可能呢?我错过了什么?

Proguard被禁用。

0 个答案:

没有答案