Only create the motor list fragment once. If it already exists, don't create it again. This was causing problems during orientation change by creating multiple overlapping lists.

This commit is contained in:
Kevin Ruland 2012-02-17 22:10:28 +00:00
parent 8e845590a8
commit b1891e1dc1

View File

@ -21,6 +21,7 @@ implements MotorListFragment.OnMotorSelectedListener
MotorListFragment motorList;
private final static int DOWNLOAD_REQUEST_CODE = 1;
private final static String MOTOR_LIST_FRAGMENT = "motor_list";
/** Called when the activity is first created. */
@Override
@ -28,13 +29,20 @@ implements MotorListFragment.OnMotorSelectedListener
super.onCreate(savedInstanceState);
setContentView(R.layout.motorbrowser);
getActionBarHelper().setDisplayHomeAsUpEnabled(true);
getSupportFragmentManager().beginTransaction().add( R.id.motorBrowserList, new MotorListFragment()).commit();
// Only create the motorBrowser fragment if it doesn't already exist.
Fragment motorBrowser = getSupportFragmentManager().findFragmentByTag(MOTOR_LIST_FRAGMENT);
if ( motorBrowser == null ) {
getSupportFragmentManager()
.beginTransaction()
.add( R.id.motorBrowserList, new MotorListFragment(), MOTOR_LIST_FRAGMENT)
.commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.motor_browser_option_menu, menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.motor_browser_option_menu, menu);
return true;
}