开发者

Add a footer to a ListView in code

I am writing an app with a ListActivity with a footer whose contents are pretty dynamic based on certain situations. I wanted to use setFooterView like this:

Butt开发者_运维知识库on addButton = new Button(this);
addButton.setText("Add");
addButton.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 35));
lv.addFooterView(addButton, null, true);

But it causes a Runtime exception. While using a layoutInflater may work with an XML layout (I use that for the header), how do I add a footer with programmatically constructed views?


View            footerview;

footerview  = getLayoutInflater().inflate(R.layout.listfooter, null);

Listview    = (ListView)findViewById(R.id.listview);
Listview.setAdapter(adp);

......

....


Listview.addFooterView(footerview);

I think this might be useful .

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜