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 (e.g.
MyTaskActivity). Add it to yourAndroidManifest.xmlin theapplicationtag:And call this in
onOptionsItemSelected: