简体   繁体   中英

Change Activity layout

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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