I'm new in Android. I stumbled on connecting tabs from menu with code.
Here is my menu.xml file:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/multiTouchExample"
android:title="MultiTouch"
android:icon="@drawable/ic_multitouch_grey"
android:showAsAction="ifRoom">
</item>
</menu>
And here is my MyActivity.java:
//includes
public class MyActivity extends Activity {
final String LOG_TAG = "TAGLogs";
ActionBar actionBar;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
actionBar = this.getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Log.d(LOG_TAG, "OnCreate start");
Log.d(LOG_TAG, new Integer(actionBar.getTabCount()).toString());
}
}
And This I have in logcat:
> D/TAGLogs﹕ OnCreate start
> D/TAGLogs﹕ 0
So it says me, that I have 0 tabs, but I have 1 in menu.xml and see it when run the program. Where is it? What I need to do?
This is screenshot of working:
UPDATE: When I want to link button from res/layout/main.xml with code:
button = (Button) findViewById(R.id.button);
So I don't create button with operator new in code. Is there some way to solve this problem like with button?