3

リストビューと別のアクティビティを含むタブがあります。それが私のコードです:

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);

タブ0のリストが空の場合、メッセージまたはTextViewを表示するにはどうすればよいですか?

4

1 に答える 1

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はテキストビューを自動的に表示します。残りのアクティビティコードはまったく同じです。

于 2012-06-10T22:46:33.710 に答える