我的活动中有一个选项卡作为视图。每个选项卡代表一个ListView
. 为了进一步澄清,ListView
s 没有任何TextView
s 膨胀。由于ListView
在 xml 模式中没有文本属性,我想知道是否可以在我的活动中执行此操作。如果没有,那么你会建议什么?
布局文件:tabworkentry.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">
<LinearLayout
android:id="@+id/tablayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Include action bar -->
<include layout="@layout/actionbar_layout"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/innerdashboard_bg"
android:layout_weight="1">
<!-- Top 10 starts -->
<ListView
android:id="@+id/Top_10"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingRight="5dp"
android:text="this is a tab" />
<!-- Top 10 ends -->
<!-- Billable starts -->
<ListView
android:id="@+id/Billable"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingRight="5dp"
android:text="this is another tab" />
<!-- Billable ends -->
<!-- Product starts -->
<ListView
android:id="@+id/Product"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingRight="5dp"
android:textSize="14sp"
android:text="this is a third tab" />
<!-- Product ends -->
</LinearLayout>
</TabHost>
和java代码:
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
try {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabworkentry);
TabHost mTabHost = getTabHost();
mTabHost.addTab(mTabHost.newTabSpec("top10").setIndicator("Top 10").setContent(R.id.Top_10));
mTabHost.addTab(mTabHost.newTabSpec("billable").setIndicator("Billable").setContent(R.id.Billable));
mTabHost.addTab(mTabHost.newTabSpec("product").setIndicator("Product").setContent(R.id.Product));
mListView = (ListView)findViewById(R.id.Top_10);
mListView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,Top_10));
mListView = (ListView)findViewById(R.id.Billable);
mListView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,Billable));
mListView = (ListView)findViewById(R.id.Product);
mListView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,Product));
} catch (Exception e) {
System.out.println("Exception" + e.getStackTrace());
Log.d(TAG, "Exception" + e.getStackTrace());
}
}