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

@ -19,8 +19,9 @@ implements MotorListFragment.OnMotorSelectedListener
{ {
MotorListFragment motorList; MotorListFragment motorList;
private final static int DOWNLOAD_REQUEST_CODE = 1; private final static int DOWNLOAD_REQUEST_CODE = 1;
private final static String MOTOR_LIST_FRAGMENT = "motor_list";
/** Called when the activity is first created. */ /** Called when the activity is first created. */
@Override @Override
@ -28,13 +29,20 @@ implements MotorListFragment.OnMotorSelectedListener
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.motorbrowser); setContentView(R.layout.motorbrowser);
getActionBarHelper().setDisplayHomeAsUpEnabled(true); 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 @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater(); MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.motor_browser_option_menu, menu); inflater.inflate(R.menu.motor_browser_option_menu, menu);
return true; return true;
} }
@ -66,10 +74,10 @@ implements MotorListFragment.OnMotorSelectedListener
@Override @Override
public void onMotorSelected(long motorId) { public void onMotorSelected(long motorId) {
View sidepane = findViewById(R.id.sidepane); View sidepane = findViewById(R.id.sidepane);
if ( /* if multi pane */ sidepane != null ) { if ( /* if multi pane */ sidepane != null ) {
Fragment graph = BurnPlotFragment.newInstance(motorId); Fragment graph = BurnPlotFragment.newInstance(motorId);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();