0

如果有可能,我怎麼能加我被分配到我的SimpleCursorAdapter(「ondemandandautomatic_authorize」)佈局上方的「頭」,和ListView控件下方的按鈕?我可以在佈局/合併佈局中使用佈局嗎?

SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, 
     R.layout.ondemandandautomatic_authorize, mContacts, 
     new String[] { ContactsContract.Contacts.DISPLAY_NAME }, 
     new int[] { R.id.contactLabel }); 

setListAdapter(mAdapter); 

我有什麼在我的活動現在顯示爲:

<AppName> 

<ckbx1><ckbx2><ckbx3><TextView (ContactName)> 
...(repeating the line above for each contact) 

但我想要的是:

<AppName> 

<TextView1><TextView2><TextView3><TextView4> 
<ckbx1> <ckbx2> <ckbx3> <TextView (ContactName)> 
...(repeating the line above for each contact) 

<Button> 

可能嗎?

回答

1

對於列表標題部分使用Listviewinstance.addHeaderView(viewtobeadded),對於頁腳部分底部的按鈕,使用ListViewinstance.addFooterView(buttontobeadded)。

請確保這些頁腳和頭添加的東西必須在您的列表視圖設置適配器之前完成。

+0

我猜「viewtobededded」可以是一個ViewGroup,所以我可以將所有這些小部件放入它? – 2012-02-10 15:09:54

1

你可能想,如果你想在列表中,here is the javadoc底部的按鈕來添加頁腳到ListView。

getListView().addFooterView(new Button(...));

setListAdapter(mAdapter);之前完成。