0

アイテムのリストを表示するだけの画面があります。私はこれを使用 setListAdapter(new ArrayAdapter<String>(ClassListActivity.this,android.R.layout.simple_list_item_1,getItems));
しましたが、この権利のために個別のxmlレイアウトを作成する必要はありません。しかし、ここで、このリストの見出しが「myItems」と表示されている可能性のあるTextViewが必要です。xmlレイアウトをこのアクティビティにリンクしようとすると、アプリケーションが停止します。ダイナミックを作成しようとするとTextView、この方法TextView tv = new TextView(this); で後でテキストを設定します。エラーは発生しませんが、古いリストに見出しがないだけで結果も得られません。

私は何をすべきか?ありがとう

4

1 に答える 1

1

ListAdapter用に独自のXMLレイアウトを作成する必要があります。TextViewを上部の見出しとして配置し、その後にidのListViewウィジェットを配置し@android:id/listます。

詳細はこちらをご覧ください:ListActivity

これは機能するはずです:

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:paddingLeft="8dp"
     android:paddingRight="8dp">

 <TextView android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:background="#FF0000"
           android:text="My list"/>

 <ListView android:id="@android:id/list"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:background="#00FF00"
           android:layout_weight="1"
           android:drawSelectorOnTop="false"/>

 </LinearLayout>
于 2012-06-04T06:38:10.323 に答える