Android Place Picker不会返回活动状态

时间:2017-09-12 12:10:44

标签: java android google-places-api

我已在我的应用中实施了PlacePicker。我有一个自定义对话框,其中包含一个寻呼机(如2个标签)。第二个寻呼机项目有EditText个组件。接触到这一点,我打开了placepicker。问题是,按下PlacePicker,关闭应用程序而不是从它开始的地方返回活动。

这是PlacePicker开始的代码

public void showPlacePicker() {
        try {
            PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
            startActivityForResult(builder.build(OrganizerMainActivity.this), PLACE_PICKER_REQUEST);
        } catch (GooglePlayServicesNotAvailableException e) {
            GoogleApiAvailability.getInstance().getErrorDialog(this, e.errorCode, PLACE_PICKER_REQUEST).show();
            e.printStackTrace();
        } catch (GooglePlayServicesRepairableException e) {
            GoogleApiAvailability.getInstance().getErrorDialog(this, e.getConnectionStatusCode(), PLACE_PICKER_REQUEST).show();
            e.printStackTrace();
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == PLACE_PICKER_REQUEST) {
            if (resultCode == RESULT_OK) {
                Place selectedPlace = PlacePicker.getPlace(this, data);
                LatLng values = selectedPlace.getLatLng();
                String loc = selectedPlace.getAddress().toString();
                eventFilters.setLat(values.latitude);
                eventFilters.setLon(values.longitude);
                eventFilters.setLocation(loc);
                eventFilters.setUseLocation(true);
                showFilterDialog();
            }

        }

    }

以这种方式从对话框的“位置”选项卡中调用showPlacePicker函数

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_filter_location, container, false);
        mProgressBar = (ProgressBar) view.findViewById(R.id.filter_location_progress);
        mInputLocation = (TextInputEditText) view.findViewById(R.id.filter_location_input_text);
        mCheckbox = (CheckBox) view.findViewById(R.id.filter_location_checkbox);
        mInputLocation.setText(eventFilters.getLocation());
        mCheckbox.setChecked(eventFilters.shouldUseLocation());
        mCheckbox.setEnabled(!eventFilters.getLocation().equals(""));
        inputLocationTouchHandler = new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        mProgressBar.setVisibility(View.VISIBLE);
                        mInputLocation.setOnTouchListener(null);
                        mListener.showPlacePicker();
                        break;
                    case MotionEvent.ACTION_UP:
                        break;
                }
                return false;
            }
        };

即使我选择了一个位置,该应用也会关闭,而不是从它开始的位置返回活动。

有人可以帮帮我吗?

0 个答案:

没有答案