Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Howto add onclick event to button in listview added by addFooterView?

Tags:

android

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

like image 953
Andy Avatar asked Feb 08 '10 14:02

Andy


1 Answers

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.

like image 90
Erich Douglass Avatar answered Oct 04 '22 03:10

Erich Douglass