user468311
user468311

Reputation:

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);

Upvotes: 6

Views: 30134

Answers (3)

Niranj Patel
Niranj Patel

Reputation: 33258

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);

Upvotes: 32

BFil
BFil

Reputation: 13096

You can use addHeaderView() and addFooterView() on your ListView

Upvotes: 7

Kamen
Kamen

Reputation: 3595

Check here:

Android Dynamically load Listview at scroll end?

This is with the help of list's footer and header. Basically, you use addHeaderView() /addFooterView (). Check all versions of the methods, since they allow you to have the view not being selectable.

Upvotes: 1

Related Questions