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).
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?
The lines are stored within the Graph View object itself which should be persistent since it is a stored variable in my activity.
I use these two methods for switching layout files on a button click.
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);
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…