更改活动布局 [英] Change Activity layout

查看:95
本文介绍了更改活动布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用我想改变的活动内容查看是否被点击,例如一个按钮。

在开始时我所说的第一辣油:

 公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.catalog);
    }

和当按钮被pressed我称它是:

 公共无效showItemActivity(INT位置){
        的setContentView(R.layout.item_view);
    }

在这个方法我的应用程序崩溃。

我需要说,如果我试试这个方法:

 的setContentView(R.layout.item_view);

在开始另一个活动中它完美地工作,但它REALI对我来说很重要,这将是在同一个活动

修改

在logchat错误信息:

 了java.lang.RuntimeException:您的内容必须有一个ListView的id属性是'android.R.id.list


解决方案

的问题是,你的活动类可能已​​经扩展ListActivity,你应该有一个ListView的id属性是 android.R.id .LIST 在布局xml文件,让你的ListActivty类可以找到这个活动的主要名单。(如果SomeClass的扩展ListActivity,这意味着SomeClass的,主要有一个列表的作用)。只需设置你的ListView的ID android.R.id.list 布局/ item_view.xml

In my app i want to change the Activity contentview if a button was clicked for example.

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.

Edit

the logchat error msg:

 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). Just set your ListView id to android.R.id.list in layout/item_view.xml.

这篇关于更改活动布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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