ListActivity を拡張してリストを作成しています。リスト内のアイテムの総数を表示するために、リストにヘッダーを追加しました。
以下に示すように、別のレイアウト ファイル header.xml でヘッダー ビューを管理しています。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/headerTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Total number of devices :"
android:textSize="15dip"
android:layout_weight="1" />
</LinearLayout>
これは、ListViewActivity クラスのリストにヘッダーを追加する方法です。
ListView lv = getListView();
LayoutInflater inflater = getLayoutInflater();
ViewGroup header = (ViewGroup)inflater.inflate(R.layout.header, lv, false);
lv.addHeaderView(header, null, false);
ヘッダー TextView のテキストを設定するにはどうすればよいですか? 以下を試してみたところ、TextView に対して null が返されました。
TextView textBox = (TextView)findViewById(R.id.);
textBox.setText("Count");