不工作setcontent视图 [英] setcontent view not working
问题描述
button.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
setContentView(R.layout.activity_chart);
}
});
您好我有上述code,其中在点击一个按钮,我想显示他们的活动activity_chart。在这个活动我想显示的图表。在这里,我打电话的方法createIntent()。但我的问题是,该图是没有得到绘制。请帮助我新的Android系统。
Hi i have the above code wherein upon clicking a button i am trying to display them activity activity_chart. In that activity i want to display a graph. Here i am calling a method createIntent(). But my problem is that the graph is not getting plotted. Please help i am new to android.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
createIntent();
}
public Intent createIntent()
{
...
}
我是调用方法正确。
Am i calling the method right.
推荐答案
一个新的活动被称为有:
A new Activity is called with:
startActivity(新意图(currentActivity.this,nextActivity.class));
然后在你的新活动的onCreate(捆绑savedInstance)
方法,你可以调用的setContentView(版面布局);
来设置新的布局。
Then in your new Activities onCreate(Bundle savedInstance)
method you can call setContentView(Layout layout);
to set the new Layout.
所以,如果你想在一个点击按钮时,更改活动,你必须做到以下几点:
So if you want to change the Activity when clicking on a Button you have to do the following:
button.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
startActivity(new Intent(currentActivity.this, nextActivity.class));
}
});
单击该按钮,当你目前只改变了电流活动的布局的不可以切换到另一个活动。
You are currently only changing the layout of the current Activity when clicking the button and not changing to another Activity.
我希望我正确地理解你。如果没有,那么我提供一些更多的code,所以我可以试着去了解你想做的事情。
I hope I understood you correctly. If not then provide me with some more code so I can try to understand what you want to do.
这篇关于不工作setcontent视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!