Note that there are some explanatory texts on larger screens.

plurals
  1. POSwitching between 2 layouts in android activity
    text
    copied!<p>I have 2 different layout files that I want to use for modifying the same data, I was to switch to my layout for the "edit view" that allows the user to modify graph data and then allow them to switch back to a "detailed view" that displays a detailed graph(using androidplot library).</p> <p>My issue is, when switching back to my "edit view" my graphed lines are gone and only the axises draw(so the layout switches and the onDraw() is being called for my graph View). Everything is stored within the same Activity so I don't understand why this isn't working?</p> <p>The lines are stored within the Graph View object itself which should be persistent since it is a stored variable in my activity.</p> <p>I use these two methods for switching layout files on a button click.</p> <pre><code>public class GraphLibActivity extends Activity { private Graph graph; private boolean editView; private static TextView coordTextView; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); editView = true; setContentView(R.layout.graphlib); graph = (Graph) findViewById(R.id.graph); coordTextView = (TextView)findViewById(R.id.currentCoords); (lots of calculations) graph.addLine(gelHistogramPoints, linePaint); graph.invalidate(); } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); if(editView == true){ inflater.inflate(R.menu.activity_menu, menu); }else{ inflater.inflate(R.menu.detailed_view_menu, menu); } return true; } public boolean onPrepareOptionsMenu(Menu menu){ menu.clear(); MenuInflater inflater = getMenuInflater(); if(editView == true){ inflater.inflate(R.menu.activity_menu, menu); }else{ inflater.inflate(R.menu.detailed_view_menu, menu); } graph.invalidate(); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { case R.id.detailed_view: editView = false; setContentView(R.layout.imagegraph); return true; case R.id.edit_view: editView = true; setContentView(R.layout.editgraph); return true; default: return super.onOptionsItemSelected(item); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload