Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

Android listview with header and footer buttons

folks! I need to make such layout: I've got listview and I need to put buttons on top and on the bottom of it, i.e. when user scrolls list to the end, he can see bottom button, and when user is on the top of list, he can see top button. But when user is 'in the middle' of listview, he can't see those buttons. I've got no idea how to do it. Thanks for help.

UPDATE

listView=(ListView)findViewById(R.id.listSearchResults);

        LayoutInflater inflater=this.getLayoutInflater();

        View header=inflater.inflate(R.layout.list_header, null);

        btnBack=(Button)header.findViewById(R.id.btnBack);
        btnBack.setOnClickListener(this);
        btnBack.setEnabled(false);

        listView.addHeaderView(header);

        View footer=inflater.inflate(R.layout.list_footer, null);

        btnForward=(Button)footer.findViewById(R.id.btnForward);
        btnForward.setOnClickListener(this);
        btnForward.setEnabled(false);
        listView.addFooterView(footer);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

First create two layout file. like as footer_layout.xml & header_layout.xml and add footerview-headerview in list view

LayoutInflater inflater = activity.getLayoutInflater();
LinearLayout listFooterView = (LinearLayout)inflater.inflate(
            R.layout.footer_layout, null);

list.addFooterView(listFooterView);


LinearLayout listHeaderView = (LinearLayout)inflater.inflate(
                R.layout.header_layout, null);

    list.addHeaderView(listHeaderView);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...