2010-11-17 34 views
0

我想添加一個頭到在ListActivity中聲明的ListView的頂部,我試圖使用的方法之一包括一個LinearLayout內的ListView和ID的列表視圖爲@android:ID /列表。自定義ListActivity佈局的正確格式

我收到一個java.lang.UnsupportedOperationException:addView(查看,的LayoutParams)不是我的setContentView()在活動通話後適配器視圖

支持。我似乎無法找到問題,我認爲它與格式或什麼東西,有人可以幫我嗎?

這裏是XML:

<ListView 
    android:id="@android:id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="?android:attr/listPreferredItemHeight" 
    android:padding="0dip"> 
    <ImageView 
     android:id="@+id/icon" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_marginRight="6dip"/> 

<LinearLayout 
     android:orientation="vertical" 
     android:layout_width="224dip" 
     android:layout_weight="1" 
     android:layout_height="fill_parent" 
     android:layout_marginRight="20dip"> 
     <TextView 
      android:id="@+id/toptext" 
      android:layout_width="fill_parent" 
      android:singleLine="true" 
      android:layout_height="0dip" 
      android:layout_weight="1" 
      android:gravity="center_vertical" 
      android:textStyle="bold" 
      android:textSize="21sp" 
      android:textColor="@color/white"/> 

<TextView 
      android:layout_width="fill_parent" 
      android:layout_height="0dip" 
      android:layout_weight="1" 
      android:id="@+id/bottomtext" 
      android:textSize="19sp" 
      android:textStyle="italic" 
      android:maxLines="1"/> 
    </LinearLayout> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="100dip" 
     android:layout_weight="1" 
     android:layout_height="fill_parent"> 
     <TextView 
      android:id="@+id/toprighttext" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:textSize="18sp" 
      android:gravity="top" 
      android:textColor="@color/blue" 
     /> 
     <TextView 
      android:id="@+id/bottomrighttext" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:textSize="18sp" 
      android:gravity="bottom" 
      android:textColor="@color/red" 
     /> 
    </LinearLayout> 
</LinearLayout> 
</ListView> 
</LinearLayout> 

回答

1

你可以在你的佈局具有獨立header.xml得到它,在你的活動添加的第一個三行代碼在你onCreate方法,像下面一樣

 super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);   
     getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, 
     R.layout.brupress_header); 
     tv = (TextView) findViewById(R.id.brupress_header_text); 
     tv.setText("Header"); 
     setContentView(R.layout.list_layout); 

我希望它可以幫助你。

+0

我仍然調用setContentView,或者我使用.getListView(),因爲我擴展ListActivity? – joepetrakovich 2010-11-17 17:37:30