17
在ListActivity是可以使用this.getListView().addFooterView(footerView);
如何在Activity中使用getListView()?
,但如果我用活動它不能使用this.getListView()
我該怎麼辦?
在ListActivity是可以使用this.getListView().addFooterView(footerView);
如何在Activity中使用getListView()?
,但如果我用活動它不能使用this.getListView()
我該怎麼辦?
無論何時使用Activity
,您將your_layout.xml
設置爲您的Activity
的ContentView
。所以ListView
應該在your_layout.xml
中b。
該ListView應該有一個id屬性定義在xml文件中說:(android:id="@+id/list"
)。 你得到你的ListView
對象的一些東西像這樣:
setContentView(R.layout.your_layout);
ListView list = (ListView)findViewById(R.id.list);
list.addFooterView(view);
而當你使用ListActivity
通過調用方法
ListView list = getListView(); // OR you can do
ListView list = (ListView)findViewById(android.R.id.list); //consider the android prefix..
讓你ListView
,請注意,雖然定義任何layout.xml
爲ListActivity
你會有一個ListView
在您的佈局有這樣的事情ID:android:id="@android:id/list"
@downvoter:請寫出原因 – 2011-10-09 10:04:46
非常好的解釋Adil,謝謝 – 2012-04-02 01:13:23
非常好,我喜歡你解釋這兩種解決方案的方式。給予好評! – 2012-08-21 11:29:10