I am having trouble with a fragment not calling the landscape layout of itself. When you rotate the device, it reverts back to the previous fragment and puts this into the logcat:
A breakdown:
I am in Fragment A, press a button and am taken to Fragment B. When I rotate the device, Fragment A is shown in landscape view.
requestLayout() improperly called by android.widget.ListView{43a67d00 VFED.VC. ......ID 0,0-720,1845} during layout: running second layout pass
E/ViewRootImpl﹕ sendUserActionEvent() mView == null
If the device has already been rotated and the fragment is then selected, the landscape layout loads fine, it is just whilst you are in the fragment itself.
Here is the code for the fragment, I hope you can help!
public class nandos_Fragment extends Fragment implements View.OnClickListener {
View rootview;
MapView mMapView;
private GoogleMap googleMap;
public static Button scanBtn;
public static int retrievedResult = 0;
private static final String TAG = "MyActivity";
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootview = inflater.inflate(R.layout.nandos_layout, container, false);
scanBtn = (Button) rootview.findViewById(R.id.scan_button);
scanBtn.setOnClickListener(this);
mMapView = (MapView) rootview.findViewById(R.id.mapView);
mMapView.onCreate(savedInstanceState);
mMapView.onResume();// needed to get the map to display immediately
try {
MapsInitializer.initialize(getActivity().getApplicationContext());
} catch (Exception e) {
e.printStackTrace();
}
googleMap = mMapView.getMap();
// latitude and longitude
double latitude = 52.955491;
double longitude = -1.149885;
// create marker
MarkerOptions marker = new MarkerOptions().position(
new LatLng(latitude, longitude)).title("Nandos Nottingham!");
// Changing marker icon
marker.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_ROSE));
// adding marker
googleMap.addMarker(marker);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(52.955491, -1.149885)).zoom(15).build();
googleMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
return rootview;
}
public void onClick(View v) {
//respond to clicks
if (v.getId() == R.id.scan_button) {
//scan
if (retrievedResult == 0) {
IntentIntegrator scanIntegrator = new IntentIntegrator(getActivity());
scanIntegrator.initiateScan();
}else{}
}
}
@Override
public void onResume() {
super.onResume();
mMapView.onResume();
Random r = new Random();
int i1 = r.nextInt(80 - 65) + 65;
if (result != null) {
scanBtn.setText("Code: " + result + i1);
retrievedResult = 1;
}
}
@Override
public void onPause() {
super.onPause();
mMapView.onPause();
scanBtn.setText("Get Offer!");
retrievedResult = 0;
result = null;
}
@Override
public void onDestroy() {
Log.v(TAG, "ON DESTROY");
mMapView.onDestroy();
super.onDestroy();
}
Manifest File:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.user.ntuio" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="com.ram.googlemapsv2.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="@drawable/ntsu"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/AppTheme" >
<activity
android:name=".HomeActivity"
android:label="@string/title_activity_nav_bar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="****"/>
</application>
</manifest>