setcontent view not working

荒凉一梦 提交于 2019-12-22 20:43:11

问题


button.setOnClickListener(new View.OnClickListener(){

            public void onClick(View v){
                setContentView(R.layout.activity_chart);
            }

        });

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.


回答1:


A new Activity is called with:

startActivity(new Intent(currentActivity.this, nextActivity.class));

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.

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.



来源:https://stackoverflow.com/questions/13680418/setcontent-view-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!