简体   繁体   中英

how to make android menu , and how to open new screen when choose an item in this menu

i'am new in android programming
so wanna to ask for something
i made a menu and respond to action of menu with this code

public boolean onOptionsItemSelected(MenuItem item) {  
    // Handle item selection  
    switch (item.getItemId()) {  
    case R.id.main:    
        setContentView(R.layout.test2);   
        return true;  
    case R.id.news:       
        setContentView(R.layout.test2);             
        return true;  
    case R.id.feature:       
        setContentView(R.layout.test1);    
        return true;  
    default:  
        return super.onOptionsItemSelected(item);  
    }

all of this items turn me to a new layout , what i need is , when select an item i can make a new codes and programs

I would suggest to read the Android fundamentals article (especially the ActivatingComponents section).

A menu should start a new activity. If you want to change the content of one activity I would recommend to use tabs ( TabActivity ).


So here's what to do (or at least what I suggest):

Create a new activity (eg MyTaskActivity ). Add it to your AndroidManifest.xml in the application tag:

<activity android:name="your.pacakge.MyTaskActivity" />

And call this in onOptionsItemSelected :

startActivity(new Intent(this, MyTaskActivity.class));

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