在Android的设置内容视图 [英] Set content view in android

查看:127
本文介绍了在Android的设置内容视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 公共类CheckitoutActivity延伸活动{    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);
    }    无效的变化(){
        的setContentView(R.layout.someview);
    }
}

它不会设置的功能改变someview的看法。我究竟做错了。


解决方案

  1. 删除设置一个新的查看之前所有其他视图。

  2. 试着调试程序,我不知道的变化()是否实际上是(?)被调用。如果不是被称为比可能是,改变()不是由Android程序回调认可的,您可以写onResume()的code ....了解更多关于Activity类的此处 ..As我看到的变化()不是活动函数...

    公共类活动扩展的ApplicationContext {
         保护无效的onCreate(捆绑savedInstanceState);

     保护无效在onStart(); 保护无效onRestart(); 保护无效onResume(); 保护无效的onPause(); 保护无效的onStop(); 保护无效的onDestroy();

    }


也可以使用 @覆盖与当你实现基类的方法,这是一个很好的做法函数的定义...

public class CheckitoutActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    void change() {
        setContentView(R.layout.someview);
    }
}

It does not set the view to someview in the function change. What am i doing wrong.

解决方案

  1. Remove all other views before setting a new view.
  2. Try debugging the program, I am not sure whether the change() is actually (?) being called. If it is not being called than may be, change() is not recognized by android process callback... You can write your code in onResume().... learn more about Activity class here..As I see change() is not a function in Activity...

    public class Activity extends ApplicationContext { protected void onCreate(Bundle savedInstanceState);

     protected void onStart();
    
     protected void onRestart();
    
     protected void onResume();
    
     protected void onPause();
    
     protected void onStop();
    
     protected void onDestroy();
    

    }

also use @Override with function definitions when you are implementing base class's methods that is a good practice...

这篇关于在Android的设置内容视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆