从一个活动传递给另一个活动 [英] pass view from one activity to another
问题描述
在我的第一个活动中, 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);
在第二个活动中,整个布局重新启动,我不想发生:(
任何帮助都会被认可!
只需在第二个内容视图中添加相同的xml即可。如果必须在多个视图中使用布局的特定部分,请将其放入单独的xml中并包含它。
I'm trying to pass a view from one activity to another activity.
In my 1st activity, onButtonClick
, I'm navigating to another activity by using Intent
.
I've written this line setContentView(R.layout.main);
in 1st activity and also declared a graphView
.
Now the problem is, I want to populate the graphView
in the second activity but it's reference i.e. mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
is present in 1st activity.
So how can I acess mySimpleXYPlot
in 2nd activity?
if I use
setContentView(R.layout.main);
mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
in 2nd activity, whole layout gets restarted which I don't want to happen :(
ANY HELP WILL BE APPRICIATED !
Simply add the same xml in the second content view. If you have to use a specific part of your layout in more then one view put it in an separate xml and include it.
这篇关于从一个活动传递给另一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!