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);之前完成。