2011-04-26 54 views
0

ListView實例是佈局的一部分。如何充氣ListView對象

<TabWidget android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0" 
    /> 
    <FrameLayout android:id="@android:id/tabcontent" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 

     <LinearLayout android:id="@+id/launch" 
         android:orientation="vertical" 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content"> 
       <ListView android:id="@+id/resultlist" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:footerDividersEnabled="true" > 
       </ListView>       
       <Button android:id="@+id/start" 
         android:text="Predict!" 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
       /> 
     </LinearLayout> 
     ... 

    </FrameLayout> 
</LinearLayout> 

我想充氣使用id = resultlist的元素。當然,我已經爲ListView的內容字符串開發了特殊的適配器和佈局。該代碼看起來像

ListView view = (ListView) findViewById(R.id.resultlist); 
    MyAdapter adapter = new MyAdapter(
     new MyItem(R.drawable.class_01, "AUTO", 1, 0.0f), 
     new MyItem(R.drawable.class_02, "BUS", 2, 0.0f), 
    ); 
    view.setAdapter(adapter); 
    setContentView(view); 

但它工作不正確。設備上看不到任何東西。 (我敢肯定,我必須在這裏使用我的xml佈局ListView字符串和LayoutInflater實例,但在哪裏???)

謝謝。

回答

0

你是否在整個活動佈局上調用了「setContentView」?如果不是,那很可能會解釋這個問題。