简体   繁体   English

更改活动布局

[英]Change Activity layout

In my app i want to change the Activity contentview if a button was clicked for example. 在我的应用中,例如,如果单击一个按钮,我想更改“活动”内容contentview

In the begining i call the first layou: 首先,我称第一位拉尤:

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.catalog);
    }

and when a button was pressed i call this one: 当按下按钮时,我称之为:

    public void showItemActivity(int position){
        setContentView(R.layout.item_view);
    }

and in this method my app crash. 然后我的应用崩溃了

i need to say that if i try this method: 我需要说的是,如果我尝试这种方法:

setContentView(R.layout.item_view);

in the begin of another Activity it work perfectly, but it reali important for me that it will be in the same Activity . 在另一个Activity的开头,它可以完美运行,但是对我来说,很重要的一点是,它将在同一个Activity

Edit 编辑

the logchat error msg: Logchat错误消息:

 java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

The problem is that your activity class may have extended ListActivity, and you should have a ListView whose id attribute is android.R.id.list in your layout xml file, so that your ListActivty class can find the main list of this activity.(if someClass extends ListActivity, it means that someClass, mainly has the role of a list). 问题在于您的活动类可能具有扩展的ListActivity,并且您应该在布局xml文件中拥有一个id属性为android.R.id.list的ListView,以便您的ListActivty类可以找到此活动的主列表。如果someClass扩展了ListActivity,则意味着someClass主要具有列表的作用。 Just set your ListView id to android.R.id.list in layout/item_view.xml . 只需在layout/item_view.xml ListView id设置为android.R.id.list layout/item_view.xml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM