3

我有一个包含列表视图和另一个活动的选项卡。这是我的代码:在Tab中显示空ListView的消息 - Android

TabHost tabHost = getTabHost(); 
TabHost.TabSpec spec; 
Intent intent; 

intent = new Intent().setClass(this, ListNoteActivity.class); 
spec = tabHost.newTabSpec("list").setIndicator(getString(R.string.list), 
res.getDrawable(R.drawable.ic_tab_new)).setContent(intent); 
tabHost.addTab(spec); 

intent = new Intent().setClass(this, NewNoteActivity.class); 
spec = tabHost.newTabSpec("view").setIndicator(getString(R.string.view), 
res.getDrawable(R.drawable.ic_tab_new)).setContent(intent); 
tabHost.addTab(spec); 

tabHost.setCurrentTab(0); 

如何显示消息或TextView如果我的列表中选项卡0是空的?

回答

2

在你ListActivity,设置此布局的内容视图:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <ListView android:id="@+id/android:list" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 
    </ListView> 

    <TextView android:id="@android:id/empty" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:text="No Items!"/> 
</LinearLayout> 

如果列表视图是空的ListActivity会自动显示文本视图。其余的活动代码仍然完全相同。

+0

你能以编程方式在消息textview上设置文本吗? – AKh