Android地方选择器无法正常工作

时间:2016-05-02 16:02:29

标签: android android-fragments navigation-drawer google-places-api

我有一个带有导航抽屉的活动(HomeActivity)。每次点击导航抽屉项目时,片段都会加载到活动中。 我有一个使用Place picker的片段,然后在按钮上单击地方选择器loads.I无法在片段中加载地方选择器。

public class FindRides extends Fragment
{
    int PLACE_PICKER_REQUEST = 1;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        // inflat and return the layout
        View v = inflater.inflate(R.layout.fragment_find_rides, container, false);
        Button b;
        b= (Button) v.findViewById(R.id.req_rides);
        b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(), "OK", Toast.LENGTH_SHORT).show();
                PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
                try {
                    Intent intent = builder.build(getActivity());
                    startActivityForResult(builder.build(getActivity()), PLACE_PICKER_REQUEST);
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(getActivity(), "eXCEPTION fOUND", Toast.LENGTH_SHORT).show();
                }
            }    
        });
        return v;
    }
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == PLACE_PICKER_REQUEST) {
            if (resultCode == Activity.RESULT_OK) {
                Place place = PlacePicker.getPlace(data, getActivity());
                String toastMsg = String.format("Place: %s", place.getName());
                Toast.makeText(getActivity(), toastMsg, Toast.LENGTH_LONG).show();
            }
        }
    }
}

地点选择器未显示。引发异常。

0 个答案:

没有答案