将视图从一个活动传递到另一个活

GAM*_*AMA 5 java android graph view android-activity

我正在尝试将视图从一个活动传递到另一个活动.

在我的第一个活动中onButtonClick,我正在使用导航到另一个活动Intent.

setContentView(R.layout.main);在第一个活动中写了这一行,并宣布了一个graphView.

现在的问题是,我想填充graphView第二个活动,但它的参考即mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);存在于第一个活动中.

那么我怎样才能mySimpleXYPlot参加第二项活动?

如果我使用

 setContentView(R.layout.main);
 mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
Run Code Online (Sandbox Code Playgroud)

在第二个活动中,整个布局重新启动,我不想发生:(

任何帮助都将得到满足!

sch*_*gel 0

只需在第二个内容视图中添加相同的 xml 即可。如果您必须在多个视图中使用布局的特定部分,请将其放入单独的 xml 中并包含它。