У меня есть приложение, которое содержит несколько фрагментов в одном упражнении.
И один из фрагментов реализован картой с текстом редактирования для автоматического заполнения адреса пользователя на основе прослушивателя смены камеры, в то время как я возвращаюсь из этого фрагмента карты, которым управляючтобы вернуться к предыдущему фрагменту, но как только я щелкнул по редактировать текст в этом фрагменте карты, нажал кнопку назад, закрывая все приложение без принудительного закрытияЯ не знаю точную проблему.Извините за мой плохой английский.
public class Maps extends Fragment implements OnMapReadyCallback {
Unbinder unbinder;
@BindView(R.id.address_submit)
Button addressSubmit;
private GoogleMap mMap;
IDU idu;
User user;
EditText addressDoor, addressAddressline, addressStreet, addressCity, addressPincode, addressState;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_maps, container, false);
unbinder = ButterKnife.bind(this, rootView);
Activity_Dashboard.navigation.hideBottomNavigation();
idu = new IDU_Presenter(this, getActivity());
user = SharedPreferenceManager.getInstance(getActivity()).getUser();
addressDoor = (EditText)rootView.findViewById(R.id.address_door);
addressAddressline = (EditText)rootView.findViewById(R.id.address_addressline);
addressStreet = (EditText)rootView.findViewById(R.id.address_street);
addressCity = (EditText)rootView.findViewById(R.id.address_city);
addressState = (EditText)rootView.findViewById(R.id.address_state);
addressPincode = (EditText)rootView.findViewById(R.id.address_pincode);
final RippleBackground rippleBackground = (RippleBackground) rootView.findViewById(R.id.content);
ImageView b = (ImageView) rootView.findViewById(R.id.confirm_address_map_custom_marker);
rippleBackground.startRippleAnimation();
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
if (mMap == null) {
SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
rootView.setFocusableInTouchMode(true);
rootView.requestFocus();
rootView.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// Log.i(tag, "keyCode: " + keyCode);
if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
Fragment_Address_list fragment = new Fragment_Address_list();
FragmentActivity activitys = (FragmentActivity) getActivity();
FragmentManager fm = activitys.getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.frame_layout, fragment);
ft.commit();
return true;
}
return false;
}
});
return rootView;
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
final Geocoder geocoder = new Geocoder(getActivity(), Locale.getDefault());
mMap.setOnCameraIdleListener(new GoogleMap.OnCameraIdleListener() {
@Override
public void onCameraIdle() {
double lat = mMap.getCameraPosition().target.latitude;
double lng = mMap.getCameraPosition().target.longitude;
Location startPoint = new Location("locationA");
startPoint.setLatitude(11.010519);
startPoint.setLongitude(76.986481);
Location startPoint1 = new Location("locationb");
startPoint1.setLatitude(lat);
startPoint1.setLongitude(lng);
List<Address> addresses = null;
try {
addresses = geocoder.getFromLocation(lat, lng, 1);
if (addresses.size() == 0) {
Toast.makeText(getActivity(), "Invalid location", Toast.LENGTH_SHORT).show();
} else {
if (addresses.get(0).getThoroughfare() == null) {
addressAddressline.setText(addresses.get(0).getSubLocality());
} else {
addressAddressline.setText(addresses.get(0).getThoroughfare());
}
addressStreet.setText(addresses.get(0).getSubLocality());
addressCity.setText(addresses.get(0).getLocality());
addressPincode.setText(addresses.get(0).getPostalCode());
addressState.setText(addresses.get(0).getAdminArea());
}
} catch (IOException e) {
e.printStackTrace();
}
}
});
LatLng TutorialsPoint = new LatLng(11.010519, 76.986481);
MarkerOptions markerOptions = new MarkerOptions().position(TutorialsPoint).title("Your location");
Marker mMarker = mMap.addMarker(markerOptions);
mMarker.showInfoWindow();
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(TutorialsPoint, 18f));
}