Hi at all,
I try to customize a tab and I write this code:
super.onCreate(savedInstanceState){
setContentView(R.layout.main);
TabHost mTabHost = getTabHost();
Button mytab = (Button)findViewById(R.id.mybutton);
Intent browser = new
Intent(this,com.example.Browser.CWBrowser.class);
mTabHost.addTab(mTabHost.newTabSpec("tab_test5").setIndicator(mytab).setContent(browser));
}
The main.xml doesn't have a child with "mybutton" ID, instead I have
writed a customtab.xml that contains the mybutton ID, below you can
see the files:
MAIN:XML
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:measureAllChildren="true"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="0px"
android:layout_margin="0px"
>
<TextView xmlns:android="http://schemas.android.com/apk/res/
android"
android:id="@+id/textview4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Ciaoooo!"
/>
</FrameLayout>
</LinearLayout>
</TabHost>
CUSTOMTAB.XML
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/mybutton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="test"
android:background="@drawable/buttonmarket"
/>
</LinearLayout>
Both files are inside the layout folder.
The problem is that when i call :
Button mytab = (Button)findViewById(R.id.mybutton);
that return null!
What's the problem? I used for other projects View that I defined in
other files instead main.xml.
Anyone can help me?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en