【发布时间】:2011-08-10 20:35:02
【问题描述】:
我有 2 个不同的布局文件要用于修改相同的数据,我要切换到“编辑视图”的布局,允许用户修改图形数据,然后允许他们切换回显示详细图表的“详细视图”(使用 androidplot 库)。
我的问题是,当切换回我的“编辑视图”时,我的图形线消失了,只有轴绘制(因此布局切换和 onDraw() 正在为我的图形视图调用)。一切都存储在同一个 Activity 中,所以我不明白为什么这不起作用?
这些线条存储在 Graph View 对象本身中,它应该是持久的,因为它是我的活动中的存储变量。
我使用这两种方法在单击按钮时切换布局文件。
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);
}
}
}
【问题讨论】:
标签: java android android-layout