当我从placePicker反印时出现白色背景

时间:2017-09-05 10:50:58

标签: android

我正在使用PlaceActivity启动PlacePicker,但是当我从placepicker反印后我会认为背景是该活动的默认contentView。 帮助我从活动中删除默认背景。

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String lat=getSharedPreferences(Constant.LOCATION,MODE_PRIVATE)
            .getString(Constant.LATITUDE,null);
    if(lat==null){
        PlacePicker.IntentBuilder builder=new PlacePicker.IntentBuilder();
        try {
            startActivityForResult(builder.build(this),PLACE_PICKER_REQUEST);
            return;
        } catch (GooglePlayServicesRepairableException e) {
            e.printStackTrace();
        } catch (GooglePlayServicesNotAvailableException e) {
            e.printStackTrace();
        }
    }
    else {
        String lon=getSharedPreferences(Constant.LOCATION,MODE_PRIVATE)
                .getString(Constant.LONGITUDE,null);
        displayNearbyPlaces(lat,lon);
    }

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == PLACE_PICKER_REQUEST && resultCode == RESULT_OK) {
        Place place=PlacePicker.getPlace(this,data);
        LatLng latLng=place.getLatLng();
        displayNearbyPlaces(String.valueOf(latLng.latitude),String.valueOf(latLng.longitude));
    }
}

private void displayNearbyPlaces(String lat,String lon) {

    setContentView(R.layout.activity_places);
    resources=getResources();
    mLat=lat;
    mLong=lon;
    /*Intent intent=getIntent();
    mLat=intent.getStringExtra(Constant.LATITUDE);
    mLong=intent.getStringExtra(Constant.LONGITUDE);*/
    setActionBar(R.id.main_toolbar);
    ViewPager viewPager= (ViewPager) findViewById(R.id.pager);
    LocationPagerAdapter pagerAdapter=new LocationPagerAdapter(this,getSupportFragmentManager());
    viewPager.setAdapter(pagerAdapter);
    viewPager.setOffscreenPageLimit(viewPager.getAdapter().getCount());
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tab);
    tabLayout.setSelectedTabIndicatorColor(resources.getColor(R.color.white));
    tabLayout.setTabTextColors(resources.getColor(R.color.gray),resources.getColor(R.color.white));
    tabLayout.setupWithViewPager(viewPager);
}

1 个答案:

答案 0 :(得分:0)

如果位置未知且未存储在共享首选项中,则不会设置任何内容视图。在这种情况下,在onCreate中设置一些内容视图。如果您在PlacePicker中单击后退,则无法调用displayNearbyPlaces

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == PLACE_PICKER_REQUEST && resultCode == RESULT_OK) {
        Place place=PlacePicker.getPlace(this,data);
        LatLng latLng=place.getLatLng();
        displayNearbyPlaces(String.valueOf(latLng.latitude),String.valueOf(latLng.longitude));
    }
else finish();
}