2011-06-26 81 views
0

我正在製作一個Android應用程序,差不多完成了。Android Activity可以包含一個listview嗎?

當我啓動應用程序時,我使用按鈕將我的主頁作爲活動類型執行操作。

如今,我幾乎做了,我想那會好得多更改按鈕圖像和文字,是這樣的: enter image description here

有沒有把一個列表視圖中的活動方式還是我需要重做所有這些頁面,並重新創建它們從Listview擴展而不是Activity?

回答

2

你當然可以。這對我有用。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android_orientation="horizontal" android:layout_width="fill_parent" 
android:layout_height="fill_parent" android:paddingLeft="4dip" 
android:paddingRight="5dp"> 
<ListView android:id="@+id/your_list" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"/> 
</LinearLayout > 

在Java代碼中,放在這樣的事情:

ListView listView = (ListView) findViewById(R.id.your_list);//listView should be global 
+0

我傾向於這樣做,不採用XML,但+1爲您的代碼,簡潔的答案。 –

相關問題