tags:

views:

202

answers:

1

Hi all

I'm using a listview with my own implementation of baseadapter. Before adding the main list items to the listview and setting the Adapter i add a footer, with addFooterView(), to the listview. The footer is a normal listview item with a custom view and two buttons.

And here comes my problem:

How can i add a onClick() event to this buttons? i tried it in the getView() method of my baseadapter but that does not work. :/

I need these two buttons at the bottom of my listview as back and forward buttons, cause i don't want too much items at once in the listview.

thx

+2  A: 

Since the footer is just a normal View, you should be able to inflate the view, get a handle to the Button with findViewById() and add an onClick() handler.

Assuming that your footer is an XML layout:

View footer = View.inflate(this, R.layout.footer, null);
getListView().addFooterView(foot, null, false);

Button forward = footer.findViewById(R.id.forward);
forward.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        // Perform action on click
    }
});

Hopefully, that's enough to get you started.

Erich Douglass
hi Erich, thx for your comment. Where and how can i add this handle? Can you give me a short dummycoder?
Andy
Edited to add some sample code. Hope that helps!
Erich Douglass
Hey Erich, i was sure i tested it like this before but without luck. :) anyway, thx for your time now it works. Nice to see helfull people like you. Have a nice day. I'm sure, i will need more held in the future and come back to you. ;)
Andy