TabHost里面怎么添加控件
xml代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffcc00">
<TabHost
android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<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="wrap_content"
>
<TextView
android:id="@+id/t1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="蔬菜"/>
<TextView
android:id="@+id/t2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="水果"/>
<TextView
android:id="@+id/t3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="儿歌"/>
</FrameLayout>
</LinearLayout>
</TabHost>
</RelativeLayout>
java代码:
package com.example.study;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TabHost;
public class lei extends Activity{
private TabHost tabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.lei);
tabHost = (TabHost) findViewById(R.id.tabhost);
tabHost.setup();
tabHost.addTab(tabHost.newTabSpec("蔬菜").setIndicator("蔬菜",
getResources().getDrawable(R.drawable.ic_launcher)).setContent(
R.id.t1));
tabHost.addTab(tabHost.newTabSpec("水果").setIndicator("水果")
.setContent(R.id.t2));
tabHost.addTab(tabHost.newTabSpec("儿歌").setIndicator("儿歌")
.setContent(R.id.t3));
}
}
我写的如上面的代码,实现了一个有三个tab的TabHost,怎么往Tab里面加入控件。
加入“水果”“蔬菜”的图片和“儿歌”。求解答!最好给个例子。