Android: How do I get a listview to stop treating a footer as an element in the list?

冷暖自知 提交于 2019-12-13 04:33:50

问题


I'm trying to have some text and some buttons that appears right beneath the listview (which has a custom adapter) in my activity. If the number of things in the list gets too big then it should sit on the bottom of the screen while the list view scrolls on top.

Someone suggested I make a view out of it and put it as a footer but when I do it just treats the footer as a line in the listview and it scrolls with everything else. Here is my code

View footer = getLayoutInflater().inflate(R.layout.transaction_detail_footer, null);

    TextView t=(TextView)footer.findViewById(R.id.total); 
    t.setText("Total: 558");

    t= (TextView) footer.findViewById(R.id.funds);
    t.setText("Funds: 9800");

    getListView().addFooterView(footer);

    setListAdapter(new TransactionAdapter(TestLV.this,Vs,Vs));

Where Vs is a string array.

Does anyone know how to get it to work?


回答1:


That's normal behavior for a ListView. addFooterView() adds the view to the end of the list, not the bottom of the screen. (See documentation). To achieve what you hope to see, you'll need to place another fixed View below the ListView -- for example, a LinearLayout containing the ListView at the top and another LinearLayout at the bottom.



来源:https://stackoverflow.com/questions/18450958/android-how-do-i-get-a-listview-to-stop-treating-a-footer-as-an-element-in-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!